Esempio n. 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);
        }
Esempio n. 2
0
 public void UpdateViewCollision(bool viewCollision)
 {
     if (perso.collSet != null)
     {
         CollSet c = perso.collSet;
         if (collSetObjects == null)
         {
             collSetObjects = new Dictionary <CollideType, GameObject[]>();
             foreach (KeyValuePair <CollideType, ZdxList> zdxListKV in c.zdxList)
             {
                 CollideType type    = zdxListKV.Key;
                 ZdxList     zdxList = zdxListKV.Value;
                 if (zdxList == null)
                 {
                     continue;
                 }
                 collSetObjects[type] = new GameObject[zdxList.entries?.Length ?? 0];
                 for (int i = 0; i < zdxList.entries?.Length; i++)
                 {
                     ZdxEntry zdx = zdxList.entries[i];
                     collSetObjects[type][i] = zdx.GetGameObject(type);
                     collSetObjects[type][i].transform.SetParent(transform);
                     collSetObjects[type][i].transform.localPosition = Vector3.zero;
                     collSetObjects[type][i].transform.localRotation = Quaternion.identity;
                     collSetObjects[type][i].transform.localScale    = Vector3.one;
                 }
             }
         }
         foreach (KeyValuePair <CollideType, GameObject[]> entry in collSetObjects)
         {
             if (entry.Value != null && entry.Value.Length > 0)
             {
                 foreach (GameObject gao in entry.Value)
                 {
                     if (gao != null)
                     {
                         gao.SetActive(false);
                     }
                 }
             }
         }
         if (viewCollision)
         {
             if (state != null && c.activationList != null)
             {
                 foreach (KeyValuePair <CollideType, short> activationZone in state.zoneZdx)
                 {
                     CollideType type           = activationZone.Key;
                     short       cur_activation = activationZone.Value;
                     if (cur_activation == -1)
                     {
                         continue;
                     }
                     if (!collSetObjects.ContainsKey(type) || collSetObjects[type] == null)
                     {
                         continue;
                     }
                     if (cur_activation < 0 || cur_activation >= c.activationList.num_activationZones)
                     {
                         continue;
                     }
                     if (c.activationList.activationZones[cur_activation].num_activations == 0)
                     {
                         continue;
                     }
                     for (int i = 0; i < c.activationList.activationZones[cur_activation].activations.Length; i++)
                     {
                         uint ind_zdx = c.activationList.activationZones[cur_activation].activations[i];
                         if (collSetObjects[type].Length <= ind_zdx)
                         {
                             continue;
                         }
                         GameObject gao = collSetObjects[type][ind_zdx];
                         if (gao == null)
                         {
                             continue;
                         }
                         gao.SetActive(true);
                     }
                 }
             }
         }
     }
 }
Esempio n. 3
0
    public void UpdateViewCollision(bool viewCollision)
    {
        if (perso.collset.Value != null)
        {
            CollSet c = perso.collset.Value;
            if (collSetObjects == null)
            {
                collSetObjects = new Dictionary <CollideType, GameObject[]>();
                foreach (KeyValuePair <CollideType, Reference <ZdxList> > entry in c.zdxList)
                {
                    if (entry.Value.Value != null)
                    {
                        ZdxList zdx = entry.Value.Value;
                        collSetObjects[entry.Key] = new GameObject[zdx.num_objects];
                        if (zdx.num_objects > 0 && zdx.objects.Value != null)
                        {
                            for (int i = 0; i < zdx.objects.Value.objects.Length; i++)
                            {
                                GeometricObject geo = zdx.objects.Value.objects[i].Value;
                                if (geo == null)
                                {
                                    continue;
                                }
                                collSetObjects[entry.Key][i] = geo.GetGameObject(GeometricObject.Type.Collide, entry.Key);
                                collSetObjects[entry.Key][i].transform.SetParent(transform);
                                collSetObjects[entry.Key][i].transform.localPosition = Vector3.zero;
                                collSetObjects[entry.Key][i].transform.localRotation = Quaternion.identity;
                                collSetObjects[entry.Key][i].transform.localScale    = Vector3.one;

                                /*if(viewCollision &&
                                 * if (viewCollision && c.GetPrivilegedActionZoneStatus(entry.Key, i) == CollSet.PrivilegedActivationStatus.ForceActive) {
                                 *      col.SetVisualsActive(true);
                                 * } else {
                                 *      col.SetVisualsActive(false);
                                 * }*/
                            }
                        }
                    }
                }
            }
            foreach (KeyValuePair <CollideType, GameObject[]> entry in collSetObjects)
            {
                if (entry.Value != null && entry.Value.Length > 0)
                {
                    foreach (GameObject gao in entry.Value)
                    {
                        if (gao != null)
                        {
                            gao.SetActive(false);
                        }
                    }
                }
            }
            if (viewCollision)
            {
                foreach (KeyValuePair <CollideType, Reference <ActivationList> > entry in c.activationList)
                {
                    if (!collSetObjects.ContainsKey(entry.Key))
                    {
                        continue;
                    }
                    if (entry.Value.Value != null && entry.Value.Value.num_objects > 0 && entry.Value.Value.objects.Value != null)
                    {
                        ActivationZoneArray azr = entry.Value.Value.objects.Value;
                        if (azr.elements.Length == 0)
                        {
                            continue;
                        }
                        for (int i = 0; i < azr.elements.Length; i++)
                        {
                            if (azr.elements[i].state.Value == state)
                            {
                                ActivationZone zone = azr.elements[i].activationList.Value;
                                if (zone != null && zone.num_objects > 0 && zone.objects.Value != null)
                                {
                                    foreach (ushort act in zone.objects.Value.objects)
                                    {
                                        if (collSetObjects[entry.Key].Length > act &&
                                            collSetObjects[entry.Key][act] != null)
                                        {
                                            collSetObjects[entry.Key][act].SetActive(true);
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
    }