Beispiel #1
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);
        }
Beispiel #2
0
        public static List <SuperObject> Read(EndianBinaryReader reader, Pointer off_so, bool parseSiblings = true, bool parseChildren = true, SuperObject parent = null)
        {
            MapLoader          l            = MapLoader.Loader;
            List <SuperObject> superObjects = new List <SuperObject>();

            if (IsParsed(off_so))
            {
                return(null);
            }
            bool isFirstNode    = true;
            bool hasNextBrother = false;
            bool isValidNode    = true;

            while (isFirstNode || (hasNextBrother && parseSiblings))
            {
                SuperObject so = new SuperObject(off_so);
                superObjects.Add(so);   // Local list of superobjects (only this & siblings)
                l.superObjects.Add(so); // Global list of superobjects (all)
                if (parent != null)
                {
                    parent.children.Add(so);
                    so.parent = parent;
                }
                hasNextBrother      = false;
                so.type             = reader.ReadUInt32();
                so.off_data         = Pointer.Read(reader);
                so.off_child_first  = Pointer.Read(reader);
                so.off_child_last   = Pointer.Read(reader);
                so.num_children     = reader.ReadUInt32();
                so.off_brother_next = Pointer.Read(reader);
                so.off_brother_prev = Pointer.Read(reader);
                so.off_parent       = Pointer.Read(reader);
                so.off_matrix       = Pointer.Read(reader);
                //R3Pointer.Read(reader); // a copy of the matrix right after, at least in R3GC
                Vector3    pos   = Vector3.zero;
                Vector3    scale = Vector3.one;
                Quaternion rot   = Quaternion.identity;
                if (so.off_matrix != null)
                {
                    Pointer curPos = Pointer.Goto(ref reader, so.off_matrix);
                    so.matrix = Matrix.Read(reader, so.off_matrix);
                    pos       = so.matrix.GetPosition(convertAxes: true);
                    rot       = so.matrix.GetRotation(convertAxes: true);
                    scale     = so.matrix.GetScale(convertAxes: true);
                    Pointer.Goto(ref reader, curPos);
                }
                switch (so.type)
                {
                case 0x20:     // IPO
                    Pointer.Goto(ref reader, so.off_data);
                    so.data = IPO.Read(reader, so.off_data, so);
                    break;

                case 0x40:     // IPO
                    l.print("IPO with code 0x40 at offset " + String.Format("0x{0:X}", so.offset.offset));
                    Pointer.Goto(ref reader, so.off_data);
                    so.data = IPO.Read(reader, so.off_data, so);
                    break;

                case 0x02:     // e.o.
                    Pointer.Goto(ref reader, so.off_data);
                    so.data = Perso.Read(reader, so.off_data, so);
                    break;

                case 0x01:     // world superobject
                    so.data = World.New(so);
                    //print("parsing world superobject with " + num_children + " children");
                    break;

                case 0x04:     // sector
                    Pointer.Goto(ref reader, so.off_data);
                    so.data = Sector.Read(reader, so.off_data, so);
                    break;

                default:
                    l.print("Unknown SO type " + so.type + " at offset " + String.Format("0x{0:X}", so.offset.offset));
                    isValidNode = false;
                    break;
                }
                if (so.Gao != null)
                {
                    if (parent != null)
                    {
                        so.Gao.transform.parent = parent.Gao.transform;
                    }
                    so.Gao.transform.localPosition = pos;
                    so.Gao.transform.localRotation = rot;
                    so.Gao.transform.localScale    = scale;
                }
                isFirstNode = false;
                if (isValidNode)
                {
                    if (parseChildren && so.num_children > 0 && so.off_child_first != null)
                    {
                        //if (type == 0x01) print("parsing children now");
                        Pointer off_current = Pointer.Goto(ref reader, so.off_child_first);
                        SuperObject.Read(reader, so.off_child_first, true, true, so);
                        //R3Pointer.Goto(ref reader, off_current);
                    }
                    if (so.off_brother_next != null && !IsParsed(so.off_brother_next))
                    {
                        hasNextBrother = true;
                        Pointer.Goto(ref reader, so.off_brother_next);
                        off_so = so.off_brother_next;
                    }
                }
            }
            return(superObjects);
        }
Beispiel #3
0
 public static bool IsParsed(Pointer offset)
 {
     return(FromOffset(offset) != null);
 }
Beispiel #4
0
 public SuperObject(Pointer offset)
 {
     this.offset = offset;
     children    = new List <SuperObject>();
 }
Beispiel #5
0
 public Matrix(Pointer offset, uint type, Matrix4x4 matrix, Vector4 vec) {
     this.offset = offset;
     this.type = type;
     this.m = matrix;
     this.v = vec;
 }