Beispiel #1
0
        public cEnvCell(byte[] buffer, StreamReader inputFile, eDatFormat format, bool translateTextureIds = true)
        {
            if (format == eDatFormat.ToD)
            {
                Id = Utils.ReadUInt32(buffer, inputFile);

                Bitfield = Utils.ReadUInt32(buffer, inputFile);

                Utils.ReadUInt32(buffer, inputFile); //repeat id
            }
            else if (format == eDatFormat.retail)
            {
                Bitfield = Utils.ReadUInt32(buffer, inputFile);
                Id       = Utils.ReadUInt32(buffer, inputFile);
            }

            byte   numSurfaces = Utils.ReadByte(buffer, inputFile);
            byte   numPortals  = Utils.ReadByte(buffer, inputFile);   // Note that "portal" in this context does not refer to the swirly pink/purple thing, its basically connecting cells
            ushort numCells    = Utils.ReadUInt16(buffer, inputFile); // I believe this is what cells can be seen from this one. So the engine knows what else it needs to load/draw.

            Textures = new List <ushort>();
            // Read what surfaces are used in this cell
            for (uint i = 0; i < numSurfaces; i++)
            {
                ushort texture = Utils.ReadUInt16(buffer, inputFile);

                if (translateTextureIds)
                {
                    if (format == eDatFormat.ToD)
                    {
                        Textures.Add(texture);
                    }
                    else
                    {
                        Textures.Add(validPortalDatEntries.translateTextureId(texture));
                    }
                }
                else
                {
                    Textures.Add(texture);
                }
            }

            if (format == eDatFormat.retail)
            {
                Utils.Align(inputFile);
            }

            EnvironmentId = Utils.ReadUInt16(buffer, inputFile);

            StructId = Utils.ReadUInt16(buffer, inputFile);

            Position = new sFrame(buffer, inputFile);

            Portals = new List <cCellPortal>();
            for (int i = 0; i < numPortals; i++)
            {
                cCellPortal newPortal = new cCellPortal(buffer, inputFile);
                Portals.Add(newPortal);
            }

            if (format == eDatFormat.retail)
            {
                Utils.Align(inputFile);
            }

            Cells = new List <ushort>();
            for (uint i = 0; i < numCells; i++)
            {
                Cells.Add(Utils.ReadUInt16(buffer, inputFile));
            }

            if (format == eDatFormat.retail)
            {
                Utils.Align(inputFile);
            }

            Stabs = new List <cStab>();
            if ((Bitfield & 2) != 0)
            {
                int numStabs = Utils.ReadInt32(buffer, inputFile);

                for (int i = 0; i < numStabs; i++)
                {
                    //cStab Size is 32
                    cStab newStab = new cStab(buffer, inputFile);
                    Stabs.Add(newStab);
                }
            }

            if (format == eDatFormat.retail)
            {
                Utils.Align(inputFile);
            }

            if ((Bitfield & 8) != 0)
            {
                RestrictionObj = Utils.ReadUInt32(buffer, inputFile);
            }

            if (inputFile.BaseStream.Position != inputFile.BaseStream.Length)
            {
                throw new Exception();
            }
        }
Beispiel #2
0
        private bool compareEnvCells(cEnvCell thisEnvCell, cEnvCell otherEnvCell, bool isObjectComparison = false)
        {
            if (thisEnvCell.Id != otherEnvCell.Id)
            {
                return(false);
            }
            if (thisEnvCell.Bitfield != otherEnvCell.Bitfield)
            {
                return(false);
            }
            if (thisEnvCell.EnvironmentId != otherEnvCell.EnvironmentId)
            {
                return(false);
            }
            if (thisEnvCell.StructId != otherEnvCell.StructId)
            {
                return(false);
            }
            if (thisEnvCell.RestrictionObj != otherEnvCell.RestrictionObj)
            {
                return(false);
            }

            if (thisEnvCell.Position.angles.x != otherEnvCell.Position.angles.x)
            {
                return(false);
            }
            if (thisEnvCell.Position.angles.y != otherEnvCell.Position.angles.y)
            {
                return(false);
            }
            if (thisEnvCell.Position.angles.z != otherEnvCell.Position.angles.z)
            {
                return(false);
            }
            if (thisEnvCell.Position.angles.w != otherEnvCell.Position.angles.w)
            {
                return(false);
            }

            if (thisEnvCell.Position.origin.x != otherEnvCell.Position.origin.x)
            {
                return(false);
            }
            if (thisEnvCell.Position.origin.y != otherEnvCell.Position.origin.y)
            {
                return(false);
            }
            if (thisEnvCell.Position.origin.z != otherEnvCell.Position.origin.z)
            {
                return(false);
            }

            if (thisEnvCell.Portals.Count != otherEnvCell.Portals.Count)
            {
                return(false);
            }
            for (int i = 0; i < thisEnvCell.Portals.Count; i++)
            {
                cCellPortal thisPortal  = thisEnvCell.Portals[i];
                cCellPortal otherPortal = otherEnvCell.Portals[i];

                if (thisPortal.EnvironmentId != otherPortal.EnvironmentId)
                {
                    return(false);
                }

                if (thisPortal.Bitfield != otherPortal.Bitfield ||
                    thisPortal.OtherCellId != otherPortal.OtherCellId ||
                    thisPortal.OtherPortalId != otherPortal.OtherPortalId)
                {
                    return(false);
                }
            }

            if (thisEnvCell.Cells.Count != otherEnvCell.Cells.Count)
            {
                return(false);
            }
            for (int i = 0; i < thisEnvCell.Cells.Count; i++)
            {
                if (thisEnvCell.Cells[i] != otherEnvCell.Cells[i])
                {
                    return(false);
                }
            }

            if (thisEnvCell.Stabs.Count != otherEnvCell.Stabs.Count)
            {
                return(false);
            }
            for (int i = 0; i < thisEnvCell.Stabs.Count; i++)
            {
                cStab thisStab  = thisEnvCell.Stabs[i];
                cStab otherStab = otherEnvCell.Stabs[i];

                if (!isObjectComparison && thisStab.id != otherStab.id) //do not check thisStab.id if that's what we're converting
                {
                    return(false);
                }

                if (thisStab.frame.angles.x != otherStab.frame.angles.x)
                {
                    return(false);
                }
                if (thisStab.frame.angles.y != otherStab.frame.angles.y)
                {
                    return(false);
                }
                if (thisStab.frame.angles.z != otherStab.frame.angles.z)
                {
                    return(false);
                }
                if (thisStab.frame.angles.w != otherStab.frame.angles.w)
                {
                    return(false);
                }

                if (thisStab.frame.origin.x != otherStab.frame.origin.x)
                {
                    return(false);
                }
                if (thisStab.frame.origin.y != otherStab.frame.origin.y)
                {
                    return(false);
                }
                if (thisStab.frame.origin.z != otherStab.frame.origin.z)
                {
                    return(false);
                }
            }

            if (thisEnvCell.Textures.Count != otherEnvCell.Textures.Count)
            {
                return(false);
            }

            if (isObjectComparison) //do not check textureIds if that's what we're converting
            {
                for (int i = 0; i < thisEnvCell.Textures.Count; i++)
                {
                    if (thisEnvCell.Textures[i] != validPortalDatEntries.translateTextureId(otherEnvCell.Textures[i]))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }