Beispiel #1
0
        public static Perso Read(Reader reader, Pointer offset, SuperObject so)
        {
            MapLoader l = MapLoader.Loader;
            Perso     p = new Perso(offset, so);

            //l.print("Perso " + offset);
            l.persos.Add(p);
            p.off_3dData  = Pointer.Read(reader); // 0x0
            p.off_stdGame = Pointer.Read(reader); // 4 Standard Game info
            p.off_dynam   = Pointer.Read(reader); // 0x8 Dynam
            if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
            {
                reader.ReadUInt32();
            }
            p.off_brain   = Pointer.Read(reader); // 0xC
            p.off_camera  = Pointer.Read(reader); // 0x10 is Camera in Rayman 2
            p.off_collSet = Pointer.Read(reader); // 0x14 collset
            p.off_msWay   = Pointer.Read(reader); // 0x18
            p.off_msLight = Pointer.Read(reader); // 0x1C - MSLight
            if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
            {
                reader.ReadUInt32();
            }
            p.off_sectInfo = Pointer.Read(reader); // 0x20 // Pointer to struct that points to active sector
            reader.ReadUInt32();                   // 0x24
            reader.ReadUInt32();
            if (Settings.s.game == Settings.Game.RA || Settings.s.game == Settings.Game.RM)
            {
                reader.ReadUInt32();
            }
            if (Settings.s.engineVersion < Settings.EngineVersion.R3)
            {
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
            }

            Pointer.DoAt(ref reader, p.off_3dData, () => {
                p.p3dData = Perso3dData.Read(reader, p.off_3dData);
            });

            Pointer.DoAt(ref reader, p.off_stdGame, () => {
                p.stdGame = StandardGame.Read(reader, p.off_stdGame);
                if (Settings.s.hasObjectTypes)
                {
                    p.nameFamily = p.stdGame.GetName(0);
                    p.nameModel  = p.stdGame.GetName(1);
                    p.namePerso  = p.stdGame.GetName(2);
                }
                else
                {
                    p.nameFamily = "Family" + p.stdGame.objectTypes[0];
                    p.nameModel  = "Model" + p.stdGame.objectTypes[1];
                    p.namePerso  = "Instance" + p.stdGame.objectTypes[2];
                    if (p.p3dData != null && p.p3dData.family != null && p.p3dData.family.name == null)
                    {
                        p.p3dData.family.name         = p.nameFamily;
                        p.p3dData.family.family_index = p.stdGame.objectTypes[0];

                        if (UnitySettings.CreateFamilyGameObjects && p.p3dData.family.Gao != null)
                        {
                            p.p3dData.family.Gao.name = "[Family] " + p.nameFamily;
                        }
                    }
                }
            });

            l.print("[" + p.nameFamily + "] " + p.nameModel + " | " + p.namePerso + " - offset: " + offset + " superObject offset: " + (so != null?so.offset.ToString():"null"));
            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal && Settings.s.game != Settings.Game.R2Revolution)
            {
                Pointer.DoAt(ref reader, p.off_dynam, () => {
                    p.dynam = Dynam.Read(reader, p.off_dynam);
                });
            }

            Pointer.DoAt(ref reader, p.off_brain, () => {
                p.brain = Brain.Read(reader, p.off_brain);
                if (p.brain != null && p.brain.mind != null && p.brain.mind.AI_model != null && p.nameModel != null)
                {
                    p.brain.mind.AI_model.name = p.nameModel;
                }
            });

            /*if (l.mode == MapLoader.Mode.Rayman2PC && off_msWay != null) {
             * MS_Way is always empty at start, instead check DsgVars for graphs
             *  Pointer off_current = Pointer.Goto(ref reader, off_msWay);
             *
             *  p.msWay = MSWay.Read(reader, off_msWay);
             *  Pointer.Goto(ref reader, off_current);
             *
             *  // Graph read?
             *  if (p.msWay.graph != null) {
             *      GameObject go_msWay = new GameObject("MSWay");
             *      go_msWay.transform.SetParent(p.Gao.transform);
             *
             *      GameObject go_graph = new GameObject("Graph");
             *      go_graph.transform.SetParent(go_msWay.transform);
             *
             *      int nodeNum = 0;
             *      foreach (GraphNode node in p.msWay.graph.nodeList) {
             *          GameObject go_graphNode = new GameObject("GraphNode[" + nodeNum + "].WayPoint");
             *          go_graphNode.transform.position.Set(node.wayPoint.position.x, node.wayPoint.position.y, node.wayPoint.position.z);
             *          go_graphNode.transform.SetParent(go_graph.transform);
             *          nodeNum++;
             *      }
             *  }
             * }*/
            if (p.p3dData != null && p.p3dData.family != null)
            {
                if (p.p3dData.off_objectList != null && p.p3dData.family.GetIndexOfPhysicalList(p.p3dData.off_objectList) == -1)
                {
                    ObjectList ol = ObjectList.FromOffsetOrRead(p.p3dData.off_objectList, reader);
                    p.p3dData.family.AddNewPhysicalList(ol);

                    /*if (ol != null) {
                     *      p.p3dData.family.AddNewPhysicalList(ol);
                     *      ol.Gao.transform.SetParent(p.p3dData.family.Gao.transform);
                     * }*/
                }
                if (p.p3dData.off_objectListInitial != null && p.p3dData.family.GetIndexOfPhysicalList(p.p3dData.off_objectListInitial) == -1)
                {
                    ObjectList ol = ObjectList.FromOffsetOrRead(p.p3dData.off_objectListInitial, reader);
                    p.p3dData.family.AddNewPhysicalList(ol);

                    /*if (ol != null) {
                     *      p.p3dData.family.AddNewPhysicalList(ol);
                     *      ol.Gao.transform.SetParent(p.p3dData.family.Gao.transform);
                     * }*/
                }
                if (p.brain != null && p.brain.mind != null && p.brain.mind.AI_model != null &&
                    !(Settings.s.engineVersion == Settings.EngineVersion.R3 && Settings.s.loadFromMemory))      // Weird bug for R3 memory loading
                // Add physical objects tables hidden in scripts
                {
                    AIModel ai = p.brain.mind.AI_model;
                    if (ai.behaviors_normal != null)
                    {
                        for (int i = 0; i < ai.behaviors_normal.Length; i++)
                        {
                            if (ai.behaviors_normal[i].scripts != null)
                            {
                                for (int j = 0; j < ai.behaviors_normal[i].scripts.Length; j++)
                                {
                                    List <ScriptNode> nodes = p.brain.mind.AI_model.behaviors_normal[i].scripts[j].scriptNodes;
                                    foreach (ScriptNode node in nodes)
                                    {
                                        if (node.param_ptr != null && node.nodeType == ScriptNode.NodeType.ObjectTableRef)
                                        {
                                            ObjectList ol = ObjectList.FromOffsetOrRead(node.param_ptr, reader);
                                            ol.unknownFamilyName = p.p3dData.family.name;
                                            ol.AddToFamilyLists(p);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (ai.behaviors_reflex != null)
                    {
                        for (int i = 0; i < ai.behaviors_reflex.Length; i++)
                        {
                            if (ai.behaviors_reflex[i].scripts != null)
                            {
                                for (int j = 0; j < ai.behaviors_reflex[i].scripts.Length; j++)
                                {
                                    List <ScriptNode> nodes = p.brain.mind.AI_model.behaviors_reflex[i].scripts[j].scriptNodes;
                                    foreach (ScriptNode node in nodes)
                                    {
                                        if (node.param_ptr != null && node.nodeType == ScriptNode.NodeType.ObjectTableRef)
                                        {
                                            ObjectList ol = ObjectList.FromOffsetOrRead(node.param_ptr, reader);
                                            ol.unknownFamilyName = p.p3dData.family.name;
                                            ol.AddToFamilyLists(p);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (ai.macros != null)
                    {
                        for (int i = 0; i < ai.macros.Length; i++)
                        {
                            if (ai.macros[i].script != null)
                            {
                                List <ScriptNode> nodes = p.brain.mind.AI_model.macros[i].script.scriptNodes;
                                foreach (ScriptNode node in nodes)
                                {
                                    if (node.param_ptr != null && node.nodeType == ScriptNode.NodeType.ObjectTableRef)
                                    {
                                        ObjectList ol = ObjectList.FromOffsetOrRead(node.param_ptr, reader);
                                        ol.unknownFamilyName = p.p3dData.family.name;
                                        ol.AddToFamilyLists(p);
                                    }
                                }
                            }
                        }
                    }
                }
                if (p.p3dData.family.GetIndexOfPhysicalList(p.p3dData.off_objectList) != -1)
                {
                    p.p3dData.objectList = ObjectList.FromOffset(p.p3dData.off_objectList);
                }
            }

            Pointer.DoAt(ref reader, p.off_collSet, () => {
                p.collset = CollSet.Read(reader, p, p.off_collSet);
            });

            Pointer.DoAt(ref reader, p.off_sectInfo, () => {
                p.sectInfo = PersoSectorInfo.Read(reader, p.off_sectInfo);
            });

            return(p);
        }
Beispiel #2
0
        public static SuperObject Read(Reader reader, Pointer off_so, SuperObject parent = null)
        {
            MapLoader l = MapLoader.Loader;

            if (IsParsed(off_so))
            {
                return(null);
            }
            bool        isValidNode = true;
            SuperObject so          = new SuperObject(off_so);

            l.superObjects.Add(so); // Global list of superobjects (all)
            if (parent != null)
            {
                so.parent = parent;
            }
            so.typeCode = reader.ReadUInt32();                                                                           // 0 - 4
            so.off_data = Pointer.Read(reader);                                                                          // 4 - 8
            so.children = LinkedList <SuperObject> .ReadHeader(reader, Pointer.Current(reader), LinkedList.Type.Double); // 8 - 14

            so.off_brother_next = Pointer.Read(reader);                                                                  // 14 - 18
            so.off_brother_prev = Pointer.Read(reader);                                                                  // 18 - 1C
            so.off_parent       = Pointer.Read(reader);                                                                  // 1C - 20
            so.off_matrix       = Pointer.Read(reader);                                                                  // 0x20->0x24
            so.off_staticMatrix = Pointer.Read(reader);                                                                  // other matrix
            so.globalMatrix     = reader.ReadInt32();                                                                    // 0x28 -> 0x2C
            so.drawFlags        = SuperObjectDrawFlags.Read(reader);
            so.flags            = SuperObjectFlags.Read(reader);                                                         // 0x30->0x34
            if (Settings.s.engineVersion == Settings.EngineVersion.R3)
            {
                reader.ReadUInt32();
            }
            Pointer off_boundingVolume = Pointer.Read(reader);
            //l.print("SuperObject T" + so.typeCode + ": " + off_so + " - " + so.off_matrix);

            //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;

            Pointer.DoAt(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.DoAt(ref reader, so.off_matrix2, () => {
             *      so.matrix2 = Matrix.Read(reader, so.off_matrix2);
             *      if (so.matrix == null) {
             *              pos = so.matrix2.GetPosition(convertAxes: true);
             *              rot = so.matrix2.GetRotation(convertAxes: true);
             *              scale = so.matrix2.GetScale(convertAxes: true);
             *      }
             * });*/
            so.type = GetSOType(so.typeCode);
            switch (so.type)
            {
            case Type.IPO:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    so.data = IPO.Read(reader, so.off_data, so);
                });
                break;

            case Type.IPO_2:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    l.print("IPO with code 0x40 at offset " + so.off_data);
                    so.data = IPO.Read(reader, so.off_data, so);
                });
                break;

            case Type.PhysicalObject:
                if (!Settings.s.loadFromMemory)
                {
                    Pointer.DoAt(ref reader, so.off_data, () => {
                        so.data = PhysicalObject.Read(reader, so.off_data, so);
                    });
                }
                break;

            case Type.Perso:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    so.data = Perso.Read(reader, so.off_data, so);
                });
                break;

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

            case Type.Sector:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    so.data = Sector.Read(reader, so.off_data, so);
                });
                break;

            case Type.GeometricObject:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    so.data = Visual.GeometricObject.Read(reader, so.off_data);
                });
                break;

            case Type.GeometricShadowObject:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    so.data = Visual.GeometricShadowObject.Read(reader, so.off_data, so);
                });
                break;

            default:
                l.print("Unknown SO type " + so.typeCode + " at " + so.offset + " - " + so.off_data);
                //isValidNode = false;
                break;
            }

            Pointer.DoAt(ref reader, off_boundingVolume, () => {
                //l.print(off_boundingVolume);
                so.boundingVolume = BoundingVolume.Read(reader, off_boundingVolume, so.flags.HasFlag(SuperObjectFlags.Flags.BoundingBoxInsteadOfSphere) ?
                                                        BoundingVolume.Type.Box : BoundingVolume.Type.Sphere);
            });

            if (so.Gao != null)
            {
                if (parent != null && parent.Gao != null)
                {
                    so.Gao.transform.parent = parent.Gao.transform;
                }
                so.Gao.transform.localPosition = pos;
                so.Gao.transform.localRotation = rot;
                so.Gao.transform.localScale    = scale;

                SuperObjectComponent soc = so.Gao.AddComponent <SuperObjectComponent>();
                so.Gao.layer = LayerMask.NameToLayer("SuperObject");
                soc.so       = so;

                if (so.boundingVolume != null)
                {
                    if (so.boundingVolume.type == BoundingVolume.Type.Box)
                    {
                        BoxCollider collider = so.Gao.AddComponent <BoxCollider>();

                        collider.center  = so.boundingVolume.Center;
                        collider.center -= so.Gao.transform.position;
                        collider.size    = so.boundingVolume.Size;
                    }
                    else
                    {
                        SphereCollider collider = so.Gao.AddComponent <SphereCollider>();

                        collider.center = so.boundingVolume.Center;
                        collider.radius = so.boundingVolume.sphereRadius;
                    }
                }
            }
            if (isValidNode)
            {
                so.children.ReadEntries(ref reader, (off_child) => {
                    SuperObject child = SuperObject.Read(reader, off_child, so);
                    child.parent      = so;
                    return(child);
                }, LinkedList.Flags.HasHeaderPointers);
            }
            return(so);
        }
Beispiel #3
0
        public static SuperObject Read(Reader reader, Pointer off_so, SuperObject parent = null)
        {
            MapLoader l = MapLoader.Loader;

            if (IsParsed(off_so))
            {
                return(null);
            }
            bool        isValidNode = true;
            SuperObject so          = new SuperObject(off_so);

            l.superObjects.Add(so); // Global list of superobjects (all)
            if (parent != null)
            {
                so.parent = parent;
            }
            so.typeCode = reader.ReadUInt32();                                                                           // 0 - 4
            so.off_data = Pointer.Read(reader);                                                                          // 4 - 8
            so.children = LinkedList <SuperObject> .ReadHeader(reader, Pointer.Current(reader), LinkedList.Type.Double); // 8 - 14

            so.off_brother_next = Pointer.Read(reader);                                                                  // 14 - 18
            so.off_brother_prev = Pointer.Read(reader);                                                                  // 18 - 1C
            so.off_parent       = Pointer.Read(reader);                                                                  // 1C - 20
            so.off_matrix       = Pointer.Read(reader);                                                                  // 0x20->0x24
            so.off_staticMatrix = Pointer.Read(reader);                                                                  // other matrix
            so.globalMatrix     = reader.ReadInt32();                                                                    // 0x28 -> 0x2C
            so.drawFlags        = SuperObjectDrawFlags.Read(reader);
            so.flags            = SuperObjectFlags.Read(reader);                                                         // 0x30->0x34
            if (Settings.s.engineVersion == Settings.EngineVersion.R3)
            {
                reader.ReadUInt32();                                                        // Visual Bounding Volume?
            }
            Pointer off_boundingVolume = Pointer.Read(reader);

            //l.print("SuperObject T" + so.typeCode + ": " + off_so + " - " + so.off_matrix);

            Pointer.DoAt(ref reader, so.off_matrix, () => {
                so.matrix = Matrix.Read(reader, so.off_matrix);
            });

            /*Pointer.DoAt(ref reader, so.off_matrix2, () => {
             *      so.matrix2 = Matrix.Read(reader, so.off_matrix2);
             *      if (so.matrix == null) {
             *              pos = so.matrix2.GetPosition(convertAxes: true);
             *              rot = so.matrix2.GetRotation(convertAxes: true);
             *              scale = so.matrix2.GetScale(convertAxes: true);
             *      }
             * });*/
            so.type = GetSOType(so.typeCode);
            switch (so.type)
            {
            case Type.IPO:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    so.data = IPO.Read(reader, so.off_data, so);
                });
                break;

            case Type.IPO_2:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    l.print("IPO with code 0x40 at offset " + so.off_data);
                    so.data = IPO.Read(reader, so.off_data, so);
                });
                break;

            case Type.PhysicalObject:
                if (!Settings.s.loadFromMemory)
                {
                    Pointer.DoAt(ref reader, so.off_data, () => {
                        so.data = PhysicalObject.Read(reader, so.off_data, so);
                    });
                }
                break;

            case Type.Perso:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    so.data = Perso.Read(reader, so.off_data, so);
                });
                break;

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

            case Type.Sector:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    so.data = Sector.Read(reader, so.off_data, so);
                });
                break;

            case Type.GeometricObject:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    so.data = Visual.GeometricObject.Read(reader, so.off_data);
                });
                break;

            case Type.GeometricShadowObject:
                Pointer.DoAt(ref reader, so.off_data, () => {
                    so.data = Visual.GeometricShadowObject.Read(reader, so.off_data, so);
                });
                break;

            default:
                l.print("Unknown SO type " + so.typeCode + " at " + so.offset + " - " + so.off_data);
                //isValidNode = false;
                break;
            }

            Pointer.DoAt(ref reader, off_boundingVolume, () => {
                //l.print(so.type + " - " + so.offset + " - " + off_boundingVolume);
                if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
                {
                    so.boundingVolumeTT = GeometricObjectCollide.Read(reader, off_boundingVolume, isBoundingVolume: true);
                }
                else
                {
                    so.boundingVolume = BoundingVolume.Read(reader, off_boundingVolume, so.flags.HasFlag(SuperObjectFlags.Flags.BoundingBoxInsteadOfSphere) ?
                                                            BoundingVolume.Type.Box : BoundingVolume.Type.Sphere);
                }
            });

            if (isValidNode)
            {
                so.children.ReadEntries(ref reader, (off_child) => {
                    SuperObject child = SuperObject.FromOffsetOrRead(off_child, reader, parent: so);
                    child.parent      = so;
                    return(child);
                }, LinkedList.Flags.HasHeaderPointers);
            }
            return(so);
        }