示例#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);
        }
示例#2
0
        public static Dynamics Read(Reader reader, Pointer offset)
        {
            Dynamics dynamics = new Dynamics(offset);

            // Read data

            dynamics.field_0 = reader.ReadUInt32();
            dynamics.field_4 = reader.ReadUInt32();
            dynamics.field_8 = reader.ReadUInt32();
            dynamics.field_C = reader.ReadUInt32();

            // Determine type
            int type;

            if ((dynamics.field_C & 4) != 0)
            {
                type = 2;
            }
            else if ((dynamics.field_C & 2) != 0)
            {
                type = 1;
            }
            else
            {
                type = 0;
            }

            dynamics.type = (DynamicsType)type;

            // Process data (common)

            Pointer.Goto(ref reader, offset + 0x54);
            dynamics.off_speedVector = Pointer.Read(reader);

            Pointer.Goto(ref reader, offset + 0x78);
            dynamics.matrixA = Matrix.Read(reader, offset + 0x78);

            Pointer.Goto(ref reader, offset + 0xD0);
            dynamics.matrixB = Matrix.Read(reader, offset + 0xD0);

            // Process data (type specific)

            if (dynamics.type == DynamicsType.Type0_SMALL)
            {
            }
            else if (dynamics.type == DynamicsType.Type1_MEDIUM)
            {
            }
            else if (dynamics.type == DynamicsType.Type2_BIG)
            {
                Pointer.Goto(ref reader, dynamics.off_speedVector);
                dynamics.speedVector = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            }

            return(dynamics);
        }
示例#3
0
文件: Dynam.cs 项目: icup321/raymap
        public static Dynam Read(Reader reader, Pointer offset)
        {
            Dynam dynam = new Dynam(offset);

            //MapLoader.Loader.print("Dynam " + offset);

            dynam.off_dynamics = Pointer.Read(reader);

            if (dynam.off_dynamics != null)
            {
                Pointer.Goto(ref reader, dynam.off_dynamics);
                dynam.dynamics = Dynamics.Read(reader, dynam.off_dynamics);
            }

            return(dynam);
        }
示例#4
0
        public static PhysicalObject Read(EndianBinaryReader reader, Pointer offset)
        {
            PhysicalObject po = new PhysicalObject(offset);

            // Header
            po.off_visualSet            = Pointer.Read(reader);
            po.off_collideSet           = Pointer.Read(reader);
            po.off_visualBoundingVolume = Pointer.Read(reader);
            if (MapLoader.Loader.mode == MapLoader.Mode.Rayman2PC)
            {
                po.off_collideBoundingVolume = po.off_visualBoundingVolume;
                reader.ReadUInt32();
            }
            else
            {
                po.off_collideBoundingVolume = Pointer.Read(reader);
            }

            // Parse visual set
            if (po.off_visualSet != null)
            {
                Pointer.Goto(ref reader, po.off_visualSet);
                reader.ReadUInt32(); // 0
                ushort numberOfLOD = reader.ReadUInt16();
                ushort type        = reader.ReadUInt16();
                for (uint i = 0; i < numberOfLOD; i++)
                {
                    // if distance > the float at this offset, game engine uses next LOD if there is one
                    VisualSetLOD lod             = new VisualSetLOD();
                    Pointer      off_LODDistance = Pointer.Read(reader);
                    lod.off_data = Pointer.Read(reader);
                    reader.ReadUInt32(); // always 0?
                    reader.ReadUInt32(); // always 0?
                    if (off_LODDistance != null)
                    {
                        Pointer off_current = Pointer.Goto(ref reader, off_LODDistance);
                        lod.LODdistance = reader.ReadSingle();
                        Pointer.Goto(ref reader, off_current);
                    }
                    if (lod.off_data != null)
                    {
                        Pointer off_current = Pointer.Goto(ref reader, lod.off_data);
                        switch (type)
                        {
                        case 0:
                            lod.obj = MeshObject.Read(reader, po, lod.off_data);
                            MeshObject m = ((MeshObject)lod.obj);
                            if (m.name != "Mesh")
                            {
                                po.Gao.name = "[PO] " + m.name;
                            }
                            m.gao.transform.parent = po.Gao.transform;
                            break;

                        case 1:
                            lod.obj = UnknownGeometricObject.Read(reader, po, lod.off_data);
                            break;

                        default:
                            MapLoader.Loader.print("unknown type " + type + " at offset: " + offset);
                            break;
                        }
                        Pointer.Goto(ref reader, off_current);
                    }
                    po.visualSet.Add(lod);
                }
            }

            // Parse collide set
            if (po.off_collideSet != null)
            {
                Pointer.Goto(ref reader, po.off_collideSet);
                uint    u1       = reader.ReadUInt32(); // 0
                uint    u2       = reader.ReadUInt32(); // 0
                uint    u3       = reader.ReadUInt32(); // 0
                Pointer off_mesh = Pointer.Read(reader);
                if (off_mesh != null)
                {
                    //R3Loader.Loader.print("Collide mesh offset: " + off_mesh);
                    Pointer.Goto(ref reader, off_mesh);
                    po.collideMesh = CollideMeshObject.Read(reader, po, off_mesh);
                    po.collideMesh.gao.transform.parent = po.Gao.transform;
                }
                //R3Loader.Loader.print("Collide set: " + po.off_collideSet + " - vol: " + po.off_visualBoundingVolume);
            }
            MapLoader.Loader.physicalObjects.Add(po);
            return(po);
        }
示例#5
0
        public static State Read(EndianBinaryReader reader, Pointer offset, Family family)
        {
            MapLoader l = MapLoader.Loader;
            State     s = new State(offset, family);

            if (l.mode == MapLoader.Mode.Rayman3GC)
            {
                s.name = new string(reader.ReadChars(0x50)).TrimEnd('\0');
            }
            if (l.mode != MapLoader.Mode.RaymanArenaGC)
            {
                s.off_state_next = Pointer.Read(reader);
            }
            if (l.mode == MapLoader.Mode.Rayman3GC)
            {
                s.off_state_prev = Pointer.Read(reader);
                Pointer.Read(reader); // unknown offset, end of state array?
            }
            s.off_anim_ref = Pointer.Read(reader);
            s.off_state_transitions_first = Pointer.Read(reader);
            if (l.mode != MapLoader.Mode.RaymanArenaGC)
            {
                s.off_state_transitions_last = Pointer.Read(reader);                                         // same?
            }
            s.num_state_transitions = reader.ReadUInt32();
            reader.ReadUInt32();
            reader.ReadUInt32();
            if (l.mode != MapLoader.Mode.RaymanArenaGC)
            {
                reader.ReadUInt32();
            }
            s.off_state_auto = Pointer.Read(reader);
            Pointer.Read(reader); // fam end?
            if (l.mode != MapLoader.Mode.Rayman2PC)
            {
                s.off_cine_mapname = Pointer.Read(reader);
                s.off_cine_name    = Pointer.Read(reader);
            }
            reader.ReadByte();
            s.speed = reader.ReadByte();
            reader.ReadByte();
            reader.ReadByte();
            if (l.mode == MapLoader.Mode.Rayman2PC)
            {
                reader.ReadUInt32();
            }

            if (s.off_cine_mapname != null)
            {
                Pointer.Goto(ref reader, s.off_cine_mapname);
                s.cine_mapname = reader.ReadNullDelimitedString();
            }
            if (s.off_cine_name != null)
            {
                Pointer.Goto(ref reader, s.off_cine_name);
                s.cine_name = reader.ReadNullDelimitedString();
            }
            if (s.off_anim_ref != null)
            {
                Pointer.Goto(ref reader, s.off_anim_ref);
                s.anim_ref = AnimationReference.Read(reader, s.off_anim_ref);
            }

            return(s);
        }
示例#6
0
        public static Family Read(EndianBinaryReader reader, Pointer offset)
        {
            MapLoader l = MapLoader.Loader;
            Family    f = new Family(offset);

            f.off_family_next  = Pointer.Read(reader);
            f.off_family_prev  = Pointer.Read(reader);
            f.off_family_unk   = Pointer.Read(reader); // at this offset, start and end pointers appear again
            f.family_index     = reader.ReadUInt32();
            f.name             = l.objectTypes[0][f.family_index].name;
            f.off_states_first = Pointer.Read(reader);
            if (l.mode != MapLoader.Mode.RaymanArenaGC)
            {
                f.off_states_last = Pointer.Read(reader);
            }
            f.num_states = reader.ReadUInt32();
            if (l.mode != MapLoader.Mode.Rayman2PC)
            {
                f.off_preloadAnim_first = Pointer.Read(reader); // (0x10 blocks: next, prev, list end, a3d pointer)
                if (l.mode != MapLoader.Mode.RaymanArenaGC)
                {
                    f.off_preloadAnim_last = Pointer.Read(reader);
                }
                f.num_preloadAnim = reader.ReadUInt32();
            }
            f.off_physical_list_default = Pointer.Read(reader); // Default objects table
            f.off_physical_list_first   = Pointer.Read(reader); // first physical list
            if (l.mode != MapLoader.Mode.RaymanArenaGC)
            {
                f.off_physical_list_last = Pointer.Read(reader);                                        // last physical list
            }
            f.num_physical_lists = reader.ReadUInt32();
            if (f.off_physical_list_first == f.off_physical_list_last && f.num_physical_lists > 1)
            {
                f.num_physical_lists = 1;                                                                                    // Correction for Rayman 2
            }
            f.off_bounding_volume = Pointer.Read(reader);
            if (l.mode == MapLoader.Mode.Rayman3GC || l.mode == MapLoader.Mode.Rayman3PC)
            {
                f.off_vector4s = Pointer.Read(reader);
                f.num_vector4s = reader.ReadUInt32();
                reader.ReadUInt32();
            }
            if (l.mode == MapLoader.Mode.Rayman2PC)
            {
                reader.ReadUInt32();
                f.animBank = reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                f.properties = reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
            }
            else
            {
                reader.ReadUInt32();
                reader.ReadByte();
                reader.ReadByte();
                f.animBank   = reader.ReadByte();
                f.properties = reader.ReadByte();
            }

            f.states = new State[f.num_states];
            if (f.num_states > 0)
            {
                Pointer off_states_current = f.off_states_first;
                for (int i = 0; i < f.num_states; i++)
                {
                    Pointer.Goto(ref reader, off_states_current);
                    f.states[i] = State.Read(reader, off_states_current, f);
                    if (l.mode == MapLoader.Mode.RaymanArenaGC)
                    {
                        off_states_current = f.states[i].offset + 0x28;
                    }
                    else
                    {
                        off_states_current = f.states[i].off_state_next;
                    }
                }
            }

            f.off_physical_lists = new Pointer[f.num_physical_lists];          // Offset for each list of POs
            f.physical_objects   = new PhysicalObject[f.num_physical_lists][]; // Each list of POs. Each perso has zero/one of these lists and can switch between them.
            if (f.off_physical_list_first != null)
            {
                Pointer.Goto(ref reader, f.off_physical_list_first);
                for (uint i = 0; i < f.num_physical_lists; i++)
                {
                    f.off_physical_lists[i] = Pointer.Current(reader);
                    Pointer off_list_hdr_next = Pointer.Read(reader);
                    if (l.mode == MapLoader.Mode.Rayman3GC)
                    {
                        Pointer off_list_hdr_prev = Pointer.Read(reader);
                        Pointer off_list_hdr      = Pointer.Read(reader);
                    }
                    Pointer off_list_start = Pointer.Read(reader);
                    Pointer off_list_2     = Pointer.Read(reader); // is this a copy of the list or something?
                    ushort  num_entries    = reader.ReadUInt16();
                    reader.ReadUInt16();


                    /*// format of list_hdr:
                     * if (l.mode == MapLoader.Mode.Rayman3PC || l.mode == MapLoader.Mode.Rayman3GC) {
                     *  Pointer off_list_hdr_first = Pointer.Read(reader);
                     *  Pointer off_list_hdr_last = Pointer.Read(reader);
                     *  uint num_lists = reader.ReadUInt32(); // 1?
                     * }*/
                    if (off_list_start != null)
                    {
                        Pointer.Goto(ref reader, off_list_start);
                        f.physical_objects[i] = new PhysicalObject[num_entries];
                        for (uint j = 0; j < num_entries; j++)
                        {
                            // each entry is 0x14
                            Pointer off_po_scale = Pointer.Read(reader);
                            Pointer off_po       = Pointer.Read(reader);
                            reader.ReadUInt32();
                            reader.ReadUInt32();
                            uint lastvalue = reader.ReadUInt32();
                            if (lastvalue != 0 && off_po != null)
                            {
                                Pointer        curPos          = Pointer.Goto(ref reader, off_po);
                                PhysicalObject po              = PhysicalObject.Read(reader, off_po);
                                Vector3?       scaleMultiplier = null;
                                if (off_po_scale != null)
                                {
                                    Pointer.Goto(ref reader, off_po_scale);
                                    float x = reader.ReadSingle();
                                    float z = reader.ReadSingle();
                                    float y = reader.ReadSingle();
                                    scaleMultiplier = new Vector3(x, y, z);
                                }
                                if (po != null)
                                {
                                    f.physical_objects[i][j] = po;
                                    po.Gao.transform.parent  = f.Gao.transform;
                                    po.scaleMultiplier       = scaleMultiplier;
                                }
                                Pointer.Goto(ref reader, curPos);
                            }
                        }
                    }
                    if (off_list_hdr_next != null)
                    {
                        Pointer.Goto(ref reader, off_list_hdr_next);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            /*if (l.mode == MapLoader.Mode.Rayman3GC) {
             *  Pointer off_list_hdr_next = Pointer.Read(reader);
             *  Pointer off_list_hdr_prev = Pointer.Read(reader);
             *  Pointer off_list_hdr = Pointer.Read(reader);
             *  //if (off_list_hdr != null) Pointer.Goto(ref reader, off_list_hdr);
             * } else if (l.mode == MapLoader.Mode.Rayman3PC || l.mode == MapLoader.Mode.RaymanArenaPC) {
             *  reader.ReadUInt32(); // 0
             * } else if (l.mode == MapLoader.Mode.Rayman2PC) {
             *  Pointer off_list_hdr = Pointer.Read(reader);
             *  //if (off_list_hdr != null) Pointer.Goto(ref reader, off_list_hdr);
             * }
             * if (l.mode == MapLoader.Mode.Rayman3PC || l.mode == MapLoader.Mode.Rayman3GC) {
             *  Pointer off_list_hdr_1 = Pointer.Read(reader); // copy of off_subblocklist?
             *  Pointer off_list_hdr_2 = Pointer.Read(reader); // same?
             *  reader.ReadUInt32(); // 1?
             * }*/
            return(f);
        }
示例#7
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);
        }
示例#8
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);
        }