Пример #1
0
        public override void WriteMembers(SR1_Writer writer)
        {
            face.Write(writer);
            attr.Write(writer);
            sortPush.Write(writer);
            normal.Write(writer);

            if (IsInSignalGroup && attr.Value != 0)
            {
                Level   level   = (Level)writer.File._Structures[0];
                Terrain terrain = (Terrain)writer.File._Structures[level.terrain.Offset];
                SR1_StructureSeries <MultiSignal> signals = (SR1_StructureSeries <MultiSignal>)writer.File._Structures[level.SignalListStart.Offset];
                MultiSignal terrainSignals = null;
                foreach (MultiSignal signal in signals)
                {
                    if (signal.Start == terrain.signals.Offset)
                    {
                        terrainSignals = signal;
                        break;
                    }
                }

                // Looks like there are other things triggered besides portals/signals.
                // TODO - Figure out what, and correct here.
                if (MultiSignal != null)
                {
                    textoff.Value = (ushort)(MultiSignal.NewStart - terrainSignals.NewStart);
                }
            }

            textoff.Write(writer);
        }
Пример #2
0
        protected override void ReadReferences(SR1_Reader reader, SR1_Structure parent)
        {
            if (data.Offset != 0x00000000 && !reader.File._Structures.ContainsKey(data.Offset))
            {
                reader.BaseStream.Position = (long)data.Offset;
                INICommand tempCMD = new INICommand();
                do
                {
                    tempCMD.ReadTemp(reader);
                }while (tempCMD.command.Value != 0);

                int bufferLength = (int)reader.BaseStream.Position - (int)data.Offset;
                SR1_StructureSeries <INICommand> commands = new SR1_StructureSeries <INICommand>(bufferLength);

                reader.BaseStream.Position = (long)data.Offset;
                commands.Read(reader, null, "");

                if (reader.Level.Name == "push10")
                {
                    new SR1_Primative <int>().Read(reader, null, "");
                }
            }

            new MultiSpline().ReadFromPointer(reader, multiSpline);
        }
Пример #3
0
        protected override void ReadReferences(SR1_Reader reader, SR1_Structure parent)
        {
            SR1_Structure temp = null;

            if (numVertices.Value > 0)
            {
                new SR1_StructureArray <TVertex>(numVertices.Value).ReadFromPointer(reader, vertexList);
            }

            SR1_StructureArray <TFace> faces = new SR1_StructureArray <TFace>(0);

            if (numFaces.Value > 0)
            {
                faces = new SR1_StructureArray <TFace>(numFaces.Value);
                faces.ReadFromPointer(reader, faceList);
            }

            if (numNormals.Value > 0)
            {
                temp = new SR1_StructureArray <Normal>(numNormals.Value).SetPadding(4).ReadFromPointer(reader, normalList);

                // 2 mystery bytes after normalList. Always 0x2A and 0xCD.
                if (temp.End != 0x00000000 && !reader.File._Structures.ContainsKey(temp.End))
                {
                    reader.BaseStream.Position = temp.End;
                    new SR1_Primative <ushort>().Read(reader, null, "");

                    if (numFaces.Value <= 0)
                    {
                        new SR1_Primative <ushort>().Read(reader, null, "");
                    }
                }
            }

            new DrMoveAniTex().ReadFromPointer(reader, aniList);

            if (reader.File._Version <= SR1_File.Version.May12)
            {
                if (sbspRoot.Offset != 0 && sbspRoot.Offset < sbspStartLeaves.Offset)
                {
                    new SR1_StructureSeries <BSPNode>((int)(sbspStartLeaves.Offset - sbspRoot.Offset)).ReadFromPointer(reader, sbspRoot);
                }
            }

            StreamUnitPortalList portalList = new StreamUnitPortalList();

            portalList.ReadFromPointer(reader, StreamUnits);

            SR1_StructureSeries <TextureFT3> textures = new SR1_StructureSeries <TextureFT3>((int)(EndTextureList.Offset - StartTextureList.Offset));

            textures.ReadFromPointer(reader, StartTextureList);

            if (reader.File._Version <= SR1_File.Version.May12)
            {
                new SR1_StructureSeries <SBSPLeaf>((int)(sbspEndLeaves.Offset - sbspStartLeaves.Offset)).ReadFromPointer(reader, sbspStartLeaves);

                if (reader.IntroListDictionary.Count > 0)
                {
                    SR1_StructureList <SR1_PointerArray <Intro> > introListSet = new SR1_StructureList <SR1_PointerArray <Intro> >();

                    foreach (KeyValuePair <uint, SR1_PointerArray <Intro> > introList in reader.IntroListDictionary)
                    {
                        introListSet.Add(introList.Value);
                    }

                    introListSet.ReadFromPointer(reader, sbspEndLeaves);
                }
            }

            new SR1_StructureSeries <MorphVertex>((int)(MorphColorList.Offset - MorphDiffList.Offset)).ReadFromPointer(reader, MorphDiffList);

            int morphColorPadding = (reader.File._Version >= SR1_File.Version.May12) ? 4 : 2;

            new SR1_StructureArray <MorphColor>(numVertices.Value).SetPadding(morphColorPadding).ReadFromPointer(reader, MorphColorList);

            SR1_StructureArray <BSPTree> bspTrees = new SR1_StructureArray <BSPTree>(numBSPTrees.Value);

            bspTrees.ReadFromPointer(reader, BSPTreeArray);

            if (bspTrees.Count > 0 && faces.Count > 0)
            {
                BSPTree tree = (BSPTree)bspTrees[numBSPTrees.Value - 1];

                if (tree.ID.Value == -1 && tree.startLeaves.Offset != 0 &&
                    reader.File._Structures.ContainsKey(tree.startLeaves.Offset) &&
                    reader.Level.SignalListStart.Offset != 0 &&
                    reader.File._Structures.ContainsKey(reader.Level.SignalListStart.Offset))
                {
                    SR1_StructureSeries <BSPLeaf> leaves =
                        (SR1_StructureSeries <BSPLeaf>)reader.File._Structures[tree.startLeaves.Offset];
                    SR1_StructureSeries <MultiSignal> multiSignals =
                        (SR1_StructureSeries <MultiSignal>)reader.File._Structures[reader.Level.SignalListStart.Offset];

                    foreach (BSPLeaf leaf in leaves)
                    {
                        uint  faceIndex = (leaf.faceList.Offset - faces.Start) / 12;
                        short numFaces  = leaf.numFaces.Value;
                        for (short f = 0; f < numFaces; f++)
                        {
                            TFace tFace = (TFace)faces[(int)faceIndex + f];
                            tFace.IsInSignalGroup = true;

                            foreach (MultiSignal mSignal in multiSignals)
                            {
                                if (mSignal.Start == (signals.Offset + tFace.textoff.Value))
                                {
                                    tFace.MultiSignal = mSignal;
                                    if (mSignal.numSignals.Value > 0)
                                    {
                                        tFace.Signal = (Signal)mSignal.signalList[0];
                                    }
                                    break;
                                }
                            }

                            if (tFace.MultiSignal != null)
                            {
                                foreach (StreamUnitPortal portal in portalList.portals)
                                {
                                    if (portal.MSignalID.Value == tFace.MultiSignal.signalNum.Value)
                                    {
                                        tFace.Portal = portal;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach (TFace face in faces)
            {
                if (!face.IsInSignalGroup)
                {
                    int textureSize  = (reader.File._Version >= SR1_File.Version.May12) ? 12 : 16;
                    int textureIndex = face.textoff.Value / textureSize;
                    if (textureIndex < textures.Count)
                    {
                        face.Texture = (TextureFT3)textures[textureIndex];
                    }
                }
            }

            new SR1_PrimativeArray <ushort>(numFaces.Value).SetPadding(4).ReadFromPointer(reader, morphNormalIdx);

            if (reader.File._Version == SR1_File.Version.Retail_PC)
            {
                new UnknownPCList().ReadFromPointer(reader, unknownPCList);
            }

            if (reader.Level.Name == "cathy28")
            {
                reader.BaseStream.Position = BSPTreeArray.Offset - 1;
                bool found = false;
                while (true)
                {
                    if (reader.File._Structures.ContainsKey((uint)reader.BaseStream.Position))
                    {
                        SR1_Structure structure = reader.File._Structures[(uint)reader.BaseStream.Position];
                        if (structure.GetType() == typeof(SR1_StructureSeries <BSPNode>))
                        {
                            found = true;
                        }
                        else if (structure.GetType() != typeof(SR1_StructureSeries <BSPLeaf>))
                        {
                            break;
                        }

                        if (found)
                        {
                            reader.BaseStream.Position = structure.End;
                            continue;
                        }
                    }

                    if (found)
                    {
                        new SR1_StructureArray <BSPLeaf>(1).Read(reader, null, "");
                        break;
                    }

                    reader.BaseStream.Position--;
                }
            }
        }
Пример #4
0
        public override void MigrateVersion(SR1_File file, SR1_File.Version targetVersion, SR1_File.MigrateFlags migrateFlags)
        {
            base.MigrateVersion(file, targetVersion, migrateFlags);

            if (file._Version <= SR1_File.Version.May12 && targetVersion >= SR1_File.Version.Retail_PC)
            {
                if (sbspRoot.Offset != 0)
                {
                    file._Structures.Remove(sbspRoot.Offset);
                    sbspRoot.Offset = 0;
                }

                if (sbspStartLeaves.Offset != 0)
                {
                    file._Structures.Remove(sbspStartLeaves.Offset);
                    sbspStartLeaves.Offset = 0;
                    sbspEndLeaves.Offset   = 0;
                }
            }

            if (file._Version < SR1_File.Version.Retail_PC && targetVersion >= SR1_File.Version.Retail_PC)
            {
                if (aniList.Offset != 0)
                {
                    file._Structures.Remove(aniList.Offset);
                    aniList.Offset        = 0;
                    EndTextureList.Offset = MorphDiffList.Offset;
                }

                SR1_Structure lastStructure = file._Structures.Values[file._Structures.Count - 1];
                uint          position      = lastStructure.End;

                unknownPCList.Offset = position;
                UnknownPCList newUnknownPCList = new UnknownPCList();
                file._Structures.Add(position, newUnknownPCList);
                file._MigrationStructures.Add(position, newUnknownPCList);
            }

            if ((migrateFlags & SR1_File.MigrateFlags.ForceWaterTranslucent) != 0)
            {
                if (numFaces.Value > 0 && faceList.Offset != 0 && file._Structures.ContainsKey(faceList.Offset) &&
                    StartTextureList.Offset != 0 && file._Structures.ContainsKey(StartTextureList.Offset))
                {
                    SR1_Structure facesStruct    = file._Structures[faceList.Offset];
                    SR1_Structure texturesStruct = file._Structures[StartTextureList.Offset];

                    if (facesStruct.GetType() == typeof(SR1_StructureArray <TFace>) &&
                        texturesStruct.GetType() == typeof(SR1_StructureSeries <TextureFT3>))
                    {
                        SR1_StructureArray <TFace>       faces    = (SR1_StructureArray <TFace>)facesStruct;
                        SR1_StructureSeries <TextureFT3> textures = (SR1_StructureSeries <TextureFT3>)texturesStruct;
                        foreach (TFace face in faces)
                        {
                            if (!face.IsInSignalGroup && (face.attr.Value & 0x08) != 0)
                            {
                                int        textureSize = file._Version < SR1_File.Version.May12 ? 16 : 12;
                                TextureFT3 texture     = (TextureFT3)textures[face.textoff.Value / textureSize];
                                texture.attr.Value |= 0x0010;
                            }
                        }
                    }
                }
            }
        }