Ejemplo n.º 1
0
 public void Destroy()
 {
     //MapLoader.Loader.physicalObjects.Remove(this);
     if (visualSet != null)
     {
         visualSet = null;
     }
     if (collideMesh != null)
     {
         collideMesh = null;
     }
     if (gao != null)
     {
         GameObject.Destroy(gao);
     }
 }
Ejemplo n.º 2
0
        public static Sector Read(Reader reader, Pointer offset, SuperObject so)
        {
            MapLoader l = MapLoader.Loader;
            Sector    s = new Sector(offset, so);

            s.name = "Sector @ " + offset + ", SPO @ " + so.offset;
            //l.print(s.name);
            if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
            {
                if (Settings.s.game == Settings.Game.TTSE)
                {
                    s.isSectorVirtual = reader.ReadByte();
                    reader.ReadByte();
                    reader.ReadByte();
                    reader.ReadByte();
                }
                Pointer off_collideObj = Pointer.Read(reader);
                Pointer.DoAt(ref reader, off_collideObj, () => {
                    s.collider = GeometricObjectCollide.Read(reader, off_collideObj, isBoundingVolume: true);
                    // This has the exact same structure as a CollideMeshObject but with a sector superobject as material for the collieMeshElements
                });
                LinkedList <int> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double); // "environments list"

                LinkedList <int> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double); // "surface list"
            }
            s.persos = LinkedList <Perso> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double);

            s.staticLights = LinkedList <LightInfo> .Read(ref reader, Pointer.Current(reader),
                                                          (off_element) => {
                LightInfo li = l.FromOffsetOrRead <LightInfo>(reader, off_element);
                if (li != null)
                {
                    li.containingSectors.Add(s);
                }
                return(li);
            },
                                                          flags : LinkedList.Flags.ElementPointerFirst
                                                          | LinkedList.Flags.ReadAtPointer
                                                          | ((Settings.s.hasLinkedListHeaderPointers) ?
                                                             LinkedList.Flags.HasHeaderPointers :
                                                             LinkedList.Flags.NoPreviousPointersForDouble),
                                                          type : LinkedList.Type.Minimize
                                                          );

            s.dynamicLights = LinkedList <int> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double);

            if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
            {
                LinkedList <int> .ReadHeader(reader, Pointer.Current(reader)); // "streams list", probably related to water
            }
            s.graphicSectors = LinkedList <NeighborSector> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Minimize);

            s.collisionSectors = LinkedList <NeighborSector> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Minimize);

            s.activitySectors = LinkedList <Sector> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Minimize);

            LinkedList <int> .ReadHeader(reader, Pointer.Current(reader)); // TT says: Sound Sectors

            LinkedList <int> .ReadHeader(reader, Pointer.Current(reader)); // Placeholder

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                s.sectorBorder = BoundingVolume.Read(reader, Pointer.Current(reader), BoundingVolume.Type.Box);
                reader.ReadUInt32();
                if (Settings.s.game == Settings.Game.R2Revolution || Settings.s.game == Settings.Game.LargoWinch)
                {
                    s.isSectorVirtual = reader.ReadByte();
                    reader.ReadByte();
                    s.sectorPriority = reader.ReadByte();
                    reader.ReadByte();
                }
                else
                {
                    s.isSectorVirtual = reader.ReadByte();
                    reader.ReadByte();
                    reader.ReadByte();
                    s.sectorPriority = reader.ReadByte();
                    if (Settings.s.engineVersion <= Settings.EngineVersion.R2)
                    {
                        s.off_skyMaterial = Pointer.Read(reader);
                        s.skyMaterial     = VisualMaterial.FromOffsetOrRead(s.off_skyMaterial, reader);
                    }
                    else
                    {
                        reader.ReadUInt32();
                    }
                    reader.ReadByte();
                    if (Settings.s.hasNames)
                    {
                        s.name = reader.ReadString(0x104);
                        l.print(s.name);
                    }
                }
            }
            else
            {
                if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
                {
                    reader.ReadUInt32();
                    reader.ReadUInt32();
                    reader.ReadUInt32();
                }
                if (Settings.s.game != Settings.Game.TTSE)
                {
                    s.isSectorVirtual = reader.ReadByte();
                    reader.ReadByte();
                    reader.ReadByte();
                    reader.ReadByte();
                }
                if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
                {
                    reader.ReadUInt32(); // activation flag
                }
                Pointer off_name = Pointer.Read(reader);
                Pointer.DoAt(ref reader, off_name, () => {
                    s.name = reader.ReadNullDelimitedString() + " @ " + offset;
                });
            }

            /*if(num_subsectors_unk > 0 && off_subsector_unk_first != null) { // only for father sector
             *  R3Pointer off_subsector_next = off_subsector_unk_first;
             *  for (int i = 0; i < num_subsectors_unk; i++) {
             *      R3Pointer.Goto(ref reader, off_subsector_next);
             *      R3Pointer off_subsector = R3Pointer.Read(reader);
             *      off_subsector_next = R3Pointer.Read(reader);
             *      R3Pointer off_subsector_prev = R3Pointer.Read(reader);
             *      R3Pointer off_sector_start = R3Pointer.Read(reader);
             *      if (off_subsector != null) {
             *          sect.neighborsPointers.Add(off_subsector);
             *      }
             *  }
             * }*/

            l.sectors.Add(s);
            return(s);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        public static PhysicalObject Read(Reader reader, Pointer offset, SuperObject so = null)
        {
            PhysicalObject po = new PhysicalObject(offset, so);

            //MapLoader.Loader.print("PO @ " + offset);
            // Header
            po.off_visualSet            = Pointer.Read(reader);
            po.off_collideSet           = Pointer.Read(reader);
            po.off_visualBoundingVolume = Pointer.Read(reader);
            if (Settings.s.engineVersion > Settings.EngineVersion.TT && Settings.s.game != Settings.Game.LargoWinch)
            {
                if (Settings.s.engineVersion < Settings.EngineVersion.R3)
                {
                    po.off_collideBoundingVolume = po.off_visualBoundingVolume;
                    reader.ReadUInt32();
                }
                else
                {
                    po.off_collideBoundingVolume = Pointer.Read(reader);
                }
            }

            // Parse visual set
            Pointer.DoAt(ref reader, po.off_visualSet, () => {
                ushort numberOfLOD = 1;
                po.visualSetType   = 0;
                if (Settings.s.game == Settings.Game.LargoWinch)
                {
                    po.visualSet                = new VisualSetLOD[1];
                    po.visualSet[0]             = new VisualSetLOD();
                    po.visualSet[0].obj         = null;
                    po.visualSet[0].off_data    = po.off_visualSet;
                    po.visualSet[0].LODdistance = 5f;
                }
                else if (Settings.s.game == Settings.Game.R2Revolution)
                {
                    po.visualSet                = new VisualSetLOD[1];
                    po.visualSet[0]             = new VisualSetLOD();
                    po.visualSet[0].obj         = MapLoader.Loader.meshObjects.FirstOrDefault(p => p.offset == po.off_visualSet);
                    po.visualSet[0].off_data    = po.off_visualSet;
                    po.visualSet[0].LODdistance = 5f;
                }
                else
                {
                    if (Settings.s.platform != Settings.Platform.DC)
                    {
                        reader.ReadUInt32();                         // 0
                        numberOfLOD = reader.ReadUInt16();
                        //if (numberOfLOD > 1) MapLoader.Loader.print("Found a PO with " + numberOfLOD + " levels of detail @ " + offset);
                        po.visualSetType = reader.ReadUInt16();
                        if (numberOfLOD > 0)
                        {
                            Pointer off_LODDistances   = Pointer.Read(reader);
                            Pointer off_LODDataOffsets = Pointer.Read(reader);
                            reader.ReadUInt32();                             // always 0? RLI table offset
                            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
                            {
                                reader.ReadUInt32();                                                                                         // always 0? number of RLI
                            }
                            po.visualSet = new VisualSetLOD[numberOfLOD];
                            for (uint i = 0; i < numberOfLOD; i++)
                            {
                                po.visualSet[i] = new VisualSetLOD();
                            }
                            Pointer.DoAt(ref reader, off_LODDistances, () => {
                                for (uint i = 0; i < numberOfLOD; i++)
                                {
                                    // if distance > the float at this offset, game engine uses next LOD if there is one
                                    po.visualSet[i].LODdistance = reader.ReadSingle();
                                }
                            });
                            Pointer.DoAt(ref reader, off_LODDataOffsets, () => {
                                for (uint i = 0; i < numberOfLOD; i++)
                                {
                                    po.visualSet[i].off_data = Pointer.Read(reader);
                                }
                            });
                        }
                    }
                    else
                    {
                        // Platform = Dreamcast
                        Pointer.Read(reader);                        // Material pointer?
                        Pointer off_data = Pointer.Read(reader);
                        reader.ReadUInt32();                         // always 0?
                        reader.ReadUInt32();                         // always 0?
                        po.visualSet                = new VisualSetLOD[1];
                        po.visualSet[0].off_data    = off_data;
                        po.visualSet[0].LODdistance = 5f;
                    }
                }
                for (uint i = 0; i < numberOfLOD; i++)
                {
                    Pointer.DoAt(ref reader, po.visualSet[i].off_data, () => {
                        switch (po.visualSetType)
                        {
                        case 0:
                            if (po.visualSet[i].obj == null)
                            {
                                po.visualSet[i].obj = GeometricObject.Read(reader, po.visualSet[i].off_data);
                            }
                            GeometricObject m = ((GeometricObject)po.visualSet[i].obj);
                            if (m.name != "Mesh")
                            {
                                po.Gao.name = "[PO] " + m.name;
                            }
                            break;

                        case 1:
                            if (po.visualSet[i].obj == null)
                            {
                                po.visualSet[i].obj = MeshModificationObject.Read(reader, po, po.visualSet[i].off_data);
                            }
                            MeshModificationObject mod = po.visualSet[i].obj as MeshModificationObject;
                            if (mod != null && mod.mesh != null && mod.mesh.name != "Mesh")
                            {
                                po.Gao.name = "[PO] " + mod.mesh.name;
                            }
                            break;

                        default:
                            MapLoader.Loader.print("unknown type " + po.visualSetType + " at offset: " + offset);
                            break;
                        }
                        if (po.visualSet[i].obj.Gao != null)
                        {
                            po.visualSet[i].obj.Gao.transform.parent = po.Gao.transform;
                        }
                    });
                }
                if (numberOfLOD > 1)
                {
                    float bestLOD = po.visualSet.Min(v => v.LODdistance);
                    foreach (VisualSetLOD lod in po.visualSet)
                    {
                        if (lod.obj.Gao != null && lod.LODdistance != bestLOD)
                        {
                            lod.obj.Gao.SetActive(false);
                        }
                    }
                }
            });

            // Parse collide set
            Pointer.DoAt(ref reader, po.off_collideSet, () => {
                if (Settings.s.game == Settings.Game.R2Revolution)
                {
                    // Read collide mesh object here directly
                    po.collideMesh = GeometricObjectCollide.Read(reader, po.off_collideSet);
                    po.collideMesh.gao.transform.parent = po.Gao.transform;
                }
                else
                {
                    // Read collide set containing collide mesh
                    uint u1         = reader.ReadUInt32();             // 0, zdm
                    uint u2         = reader.ReadUInt32();             // 0, zdd
                    uint u3         = reader.ReadUInt32();             // 0, zde
                    Pointer off_zdr = Pointer.Read(reader);
                    Pointer.DoAt(ref reader, off_zdr, () => {
                        po.collideMesh = GeometricObjectCollide.Read(reader, off_zdr);
                        po.collideMesh.gao.transform.parent = po.Gao.transform;
                    });
                }
            });
            MapLoader.Loader.physicalObjects.Add(po);
            return(po);
        }
Ejemplo n.º 5
0
        public static PhysicalObject Read(Reader reader, Pointer offset, SuperObject so = null, Radiosity radiosity = null)
        {
            PhysicalObject po = new PhysicalObject(offset, so);

            //MapLoader.Loader.print("PO @ " + offset);
            // Header
            po.off_visualSet            = Pointer.Read(reader);
            po.off_collideSet           = Pointer.Read(reader);
            po.off_visualBoundingVolume = Pointer.Read(reader);
            if (Settings.s.engineVersion > Settings.EngineVersion.TT && Settings.s.game != Settings.Game.LargoWinch)
            {
                if (Settings.s.engineVersion < Settings.EngineVersion.R3)
                {
                    po.off_collideBoundingVolume = po.off_visualBoundingVolume;
                    reader.ReadUInt32();
                }
                else
                {
                    po.off_collideBoundingVolume = Pointer.Read(reader);
                }
            }

            // Parse visual set
            Pointer.DoAt(ref reader, po.off_visualSet, () => {
                ushort numberOfLOD = 1;
                po.visualSetType   = 0;
                if (Settings.s.game == Settings.Game.LargoWinch)
                {
                    po.visualSet                = new VisualSetLOD[1];
                    po.visualSet[0]             = new VisualSetLOD();
                    po.visualSet[0].obj         = null;
                    po.visualSet[0].off_data    = po.off_visualSet;
                    po.visualSet[0].LODdistance = 5f;
                }
                else if (Settings.s.game == Settings.Game.R2Revolution)
                {
                    po.visualSet                = new VisualSetLOD[1];
                    po.visualSet[0]             = new VisualSetLOD();
                    po.visualSet[0].obj         = MapLoader.Loader.meshObjects.FirstOrDefault(p => p.offset == po.off_visualSet);
                    po.visualSet[0].off_data    = po.off_visualSet;
                    po.visualSet[0].LODdistance = 5f;
                }
                else
                {
                    if (Settings.s.platform != Settings.Platform.DC)
                    {
                        reader.ReadUInt32();                         // 0
                        numberOfLOD = reader.ReadUInt16();
                        //if (numberOfLOD > 1) MapLoader.Loader.print("Found a PO with " + numberOfLOD + " levels of detail @ " + offset);
                        po.visualSetType = reader.ReadUInt16();
                        if (numberOfLOD > 0)
                        {
                            Pointer off_LODDistances   = Pointer.Read(reader);
                            Pointer off_LODDataOffsets = Pointer.Read(reader);
                            reader.ReadUInt32();                             // always 0? RLI table offset
                            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
                            {
                                reader.ReadUInt32();                                                                                         // always 0? number of RLI
                            }
                            po.visualSet = new VisualSetLOD[numberOfLOD];
                            for (uint i = 0; i < numberOfLOD; i++)
                            {
                                po.visualSet[i] = new VisualSetLOD();
                            }
                            Pointer.DoAt(ref reader, off_LODDistances, () => {
                                for (uint i = 0; i < numberOfLOD; i++)
                                {
                                    // if distance > the float at this offset, game engine uses next LOD if there is one
                                    po.visualSet[i].LODdistance = reader.ReadSingle();
                                }
                            });
                            Pointer.DoAt(ref reader, off_LODDataOffsets, () => {
                                for (uint i = 0; i < numberOfLOD; i++)
                                {
                                    po.visualSet[i].off_data = Pointer.Read(reader);
                                }
                            });
                        }
                    }
                    else
                    {
                        // Platform = Dreamcast
                        Pointer.Read(reader);                        // Material pointer?
                        Pointer off_data = Pointer.Read(reader);
                        reader.ReadUInt32();                         // always 0?
                        reader.ReadUInt32();                         // always 0?
                        po.visualSet                = new VisualSetLOD[1];
                        po.visualSet[0].off_data    = off_data;
                        po.visualSet[0].LODdistance = 5f;
                    }
                }
                int radiosityLODIndex = 0;
                for (uint i = 0; i < numberOfLOD; i++)
                {
                    Pointer.DoAt(ref reader, po.visualSet[i].off_data, () => {
                        switch (po.visualSetType)
                        {
                        case 0:
                            if (po.visualSet[i].obj == null)
                            {
                                po.visualSet[i].obj = GeometricObject.Read(reader, po.visualSet[i].off_data, radiosity: radiosity?.lod?[radiosityLODIndex++]);
                            }
                            break;

                        case 1:
                            if (po.visualSet[i].obj == null)
                            {
                                po.visualSet[i].obj = PatchGeometricObject.Read(reader, po, po.visualSet[i].off_data);
                            }
                            break;

                        default:
                            MapLoader.Loader.print("unknown type " + po.visualSetType + " at offset: " + offset);
                            break;
                        }
                    });
                }
            });

            // Parse collide set
            Pointer.DoAt(ref reader, po.off_collideSet, () => {
                if (Settings.s.game == Settings.Game.R2Revolution)
                {
                    // Read collide mesh object here directly
                    po.collideMesh = GeometricObjectCollide.Read(reader, po.off_collideSet);
                }
                else
                {
                    // Read collide set containing collide mesh
                    uint u1         = reader.ReadUInt32();             // 0, zdm
                    uint u2         = reader.ReadUInt32();             // 0, zdd
                    uint u3         = reader.ReadUInt32();             // 0, zde
                    Pointer off_zdr = Pointer.Read(reader);
                    Pointer.DoAt(ref reader, off_zdr, () => {
                        po.collideMesh = GeometricObjectCollide.Read(reader, off_zdr);
                    });
                }
            });
            MapLoader.Loader.physicalObjects.Add(po);
            return(po);
        }