예제 #1
0
        public void Write(BinaryWriter bw, Engine ver = Engine.Unknown)
        {
            Centre.Write16(bw);
            bw.Write(CollisionSize);

            bw.Write((short)Vertices.Length);
            bw.WriteArray(Vertices, x => x.Write16(bw));

            bw.Write(NumNormals);
            if (NumNormals >= 0)
                bw.WriteArray(Normals, x => x.Write16(bw));
            else 
                bw.WriteInt16Array(Lights);

            bw.Write((short)TexturedRectangles.Length);
            bw.WriteArray(TexturedRectangles, x => x.Write(bw, ver));

            bw.Write((short)TexturedTriangles.Length);
            bw.WriteArray(TexturedTriangles, x => x.Write(bw, ver));

            if (ver < Engine.TR4)
            {
                if(ColouredRectangles == null) ColouredRectangles = new QuadFace[0];
                if(ColouredTriangles == null) ColouredTriangles = new Triangle[0];

                bw.Write((short)ColouredRectangles.Length);
                bw.WriteArray(ColouredRectangles, x => x.Write(bw, ver));

                bw.Write((short)ColouredTriangles.Length);
                bw.WriteArray(ColouredTriangles, x => x.Write(bw, ver));
            }
        }
예제 #2
0
        public void Write(BinaryWriter bw, Engine ver = Engine.Unknown)
        {
            bw.Write((ushort)TransparencyFlags);
            bw.Write(TileAndFlag);

            if(ver >= Engine.TR4) bw.Write(NewFlags);

            bw.WriteArray(Vertices, x => x.Write(bw, ver));

            if (ver >= Engine.TR4)
            {
                bw.Write(OriginalU);
                bw.Write(OriginalV);

                bw.Write(Width);
                bw.Write(Height);
            }

            if (ver == Engine.TR5)
            {
                bw.Write((ushort) 0);
            }
        }
예제 #3
0
        private void Write_TR4()
        {
            writer.Write((uint)(WriteIsDemoOrUb ? 0x63345254 : 0x00345254));

            writer.Write((ushort)Textures.Length);
            writer.Write((ushort)0);
            writer.Write((ushort)0);

            byte[] buf;
            using (var ms = new MemoryStream())
            {
                using (var bw = new BinaryWriter(ms))
                    bw.WriteArray(Textures, x => x.Write(bw));
                buf = ms.ToArray();
            }
            writer.Write((uint)buf.Length); // uncompSize
            var bufComp = Helper.Encompress(buf);
            writer.Write((uint)bufComp.Length); // compSize
            writer.Write(bufComp);

            using (var ms = new MemoryStream())
            {
                using (var bw = new BinaryWriter(ms))
                    bw.WriteArray(Texture16, x => x.Write(bw));
                buf = ms.ToArray();
            }
            writer.Write((uint)buf.Length); // uncompSize
            bufComp = Helper.Encompress(buf);
            writer.Write((uint)bufComp.Length); // compSize
            writer.Write(bufComp);

            using (var ms = new MemoryStream())
            {
                using (var bw = new BinaryWriter(ms))
                    bw.WriteArray(Textures.Skip(Textures.Length - 2).Take(2), x => x.Write(bw));
                buf = ms.ToArray();
            }
            writer.Write((uint)buf.Length); // uncompSize
            bufComp = Helper.Encompress(buf);
            writer.Write((uint)bufComp.Length); // compSize
            writer.Write(bufComp);

            // Here be dragons

            using (var ms = new MemoryStream())
            {
                using (var bw = new BinaryWriter(ms))
                {
                    bw.Write((uint)0); // unused

                    bw.Write((ushort)Rooms.Length);
                    bw.WriteArray(Rooms, x => x.Write(bw, Engine.TR4));

                    bw.Write((uint)FloorData.Length);
                    bw.WriteUInt16Array(FloorData);

                    var tmpw = writer;
                    writer = bw;
                    WriteMeshData();
                    writer = tmpw;

                    bw.Write((uint)Animations.Length);
                    bw.WriteArray(Animations, x => x.Write(bw, Engine.TR4));

                    bw.Write((uint)StateChanges.Length);
                    bw.WriteArray(StateChanges, x => x.Write(bw));

                    bw.Write((uint)AnimDispatches.Length);
                    bw.WriteArray(AnimDispatches, x => x.Write(bw));

                    bw.Write((uint)AnimCommands.Length);
                    bw.WriteInt16Array(AnimCommands);

                    bw.Write((uint)MeshTreeData.Length);
                    bw.WriteUInt32Array(MeshTreeData);

                    tmpw = writer;
                    writer = bw;
                    WriteFrameMoveableData();
                    writer = tmpw;

                    bw.Write((uint)StaticMeshes.Length);
                    bw.WriteArray(StaticMeshes, x => x.Write(bw));

                    bw.Write((sbyte)'S');
                    bw.Write((sbyte)'P');
                    bw.Write((sbyte)'R');

                    bw.Write((uint)SpriteTextures.Length);
                    bw.WriteArray(SpriteTextures, x => x.Write(bw, Engine.TR4));

                    bw.Write((uint)SpriteSequences.Length);
                    bw.WriteArray(SpriteSequences, x => x.Write(bw));

                    bw.Write((uint)Cameras.Length);
                    bw.WriteArray(Cameras, x => x.Write(bw));

                    bw.Write((uint)FlybyCameras.Length);
                    bw.WriteArray(FlybyCameras, x => x.Write(bw));

                    bw.Write((uint)SoundSources.Length);
                    bw.WriteArray(SoundSources, x => x.Write(bw));

                    bw.Write((uint)Boxes.Length);
                    bw.WriteArray(Boxes, x => x.Write(bw, Engine.TR2));

                    bw.Write((uint)Overlaps.Length);
                    bw.WriteUInt16Array(Overlaps);

                    bw.WriteArray(Zones, x => x.Write(bw, Engine.TR2));

                    bw.Write((uint)AnimatedTextures.Length);
                    bw.WriteUInt16Array(AnimatedTextures);

                    bw.Write((byte)AnimatedTexturesUVCount);

                    bw.Write((sbyte)'T');
                    bw.Write((sbyte)'E');
                    bw.Write((sbyte)'X');


                    bw.Write((uint)ObjectTextures.Length);
                    bw.WriteArray(ObjectTextures, x => x.Write(bw, Engine.TR4));

                    bw.Write((uint)Items.Length);
                    bw.WriteArray(Items, x => x.Write(bw, Engine.TR4));

                    bw.Write((uint)AIObjects.Length);
                    bw.WriteArray(AIObjects, x => x.Write(bw));

                    bw.Write((ushort)DemoData.Length);
                    bw.Write(DemoData);

                    bw.WriteInt16Array(SoundMap.Resize(Constants.TR_AUDIO_MAP_SIZE_TR4));

                    bw.Write((uint)SoundDetails.Length);
                    bw.WriteArray(SoundDetails, x => x.Write(bw, Engine.TR3));

                    bw.Write((uint)SampleIndices.Length);
                    bw.WriteUInt32Array(SampleIndices);
                }
                buf = ms.ToArray();
            }

            writer.Write((uint)buf.Length); // uncompSize
            bufComp = Helper.Encompress(buf);
            writer.Write((uint)bufComp.Length); // compSize
            writer.Write(bufComp);

            writer.Write((uint)SamplesCount);
            writer.Write(SamplesData);
        }
예제 #4
0
        public void Write(BinaryWriter bw, Engine ver = Engine.Unknown)
        {
            if (ver == Engine.TR5)
            {
                // todo convert tr1-4 room to tr5 (layers) room

                bw.Write(0x414C4558); // XELA landmark
                bw.Write((uint) 0); // room data size
                var startPos = bw.BaseStream.Position; // for calculating RoomDataSize
                bw.Write(0xCDCDCDCD); // separator

                bw.Write((uint) 0); // EndSDOffset / portalOffset
                bw.Write((uint) 0); // StartSDOffset / sectorDataOffset

                bw.Write(0xCDCDCDCD); // separator

                bw.Write((uint) 0); // EndPortalOffset / staticMeshesOffset

                bw.Write((int) Offset.X);
                bw.Write((int) Offset.Y);
                bw.Write((int) -Offset.Z);
                bw.Write((int) -Y_Bottom);
                bw.Write((int) -Y_Top);

                bw.Write(Num_Z_Sectors);
                bw.Write(Num_X_Sectors);

                LightColor.WriteBGRA(bw);

                bw.Write((ushort) Lights.Length);
                bw.Write((ushort) StaticMeshes.Length);

                bw.Write((byte) ReverbInfo);
                bw.Write((byte) AlternateGroup);
                bw.Write((ushort) WaterScheme);

                bw.Write((uint) 0x00007FFF); // filler1
                bw.Write((uint) 0x00007FFF); // filler2
                bw.Write(0xCDCDCDCD); // separator4
                bw.Write(0xCDCDCDCD); // separator5
                bw.Write(0xFFFFFFFF); // filler2

                bw.Write((ushort) AlternateRoom); // todo weird TRosettaStone says it's an ushort
                bw.Write(Flags);

                bw.Write(Unknown_R1);
                bw.Write(Unknown_R2);
                bw.Write(Unknown_R3);

                bw.Write(0xCDCDCDCD); // separator7

                bw.Write(Unknown_R4a);
                bw.Write(Unknown_R4b);

                bw.Write(Room_X);
                bw.Write(Unknown_R5);
                bw.Write(Room_Z);

                bw.Write(0xCDCDCDCD); // separator8
                bw.Write(0xCDCDCDCD); // separator9
                bw.Write(0xCDCDCDCD); // separator10
                bw.Write(0xCDCDCDCD); // separator11
                bw.Write(0xCDCDCDCD); // separator12
                bw.Write(0xCDCDCDCD); // separator13

                bw.Write((uint) Triangles.Length);
                bw.Write((uint) Rectangles.Length);

                bw.Write((uint) 0); // separator14

                bw.Write((uint) (Lights.Length * (uint) Marshal.SizeOf(typeof (Light))));
                    // TODO: Check that sizeof(Light) == 88 bytes
                bw.Write((uint) Lights.Length); // NumLights2

                bw.Write(Unknown_R6);

                bw.Write(-(int) Room_Y_Top);
                bw.Write(-(int) Room_Y_Bottom);

                bw.Write((uint) Layers.Length);
                // if everything goes well, here we are at startPos + 172
                bw.BaseStream.Position += 4 * 4; // We'll write the offsets later

                bw.Write((uint) Vertices.Length);

                bw.Write(0xCDCDCDCD); // separator15
                bw.Write(0xCDCDCDCD); // separator16
                bw.Write(0xCDCDCDCD); // separator17
                bw.Write(0xCDCDCDCD); // separator18

                var start216 = bw.BaseStream.Position; // if everything goes well we're at pos 216, otherwise, we die

                bw.WriteArray(Lights, x => x.Write(bw, Engine.TR5));

                var tmpPos = bw.BaseStream.Position;
                bw.BaseStream.Position = startPos + 8;
                bw.Write((uint) (tmpPos - start216)); // StartSDOffset
                bw.BaseStream.Position = tmpPos;

                bw.WriteArray(Sectors, x => x.Write(bw));

                tmpPos = bw.BaseStream.Position;
                bw.BaseStream.Position = startPos + 4;
                bw.Write((uint) (tmpPos - start216)); // EndSDOffset
                bw.BaseStream.Position = tmpPos;

                bw.Write((short) Portals.Length);
                bw.WriteArray(Portals, x => x.Write(bw));

                tmpPos = bw.BaseStream.Position;
                bw.BaseStream.Position = startPos + 16;
                bw.Write((uint) (tmpPos - start216)); // EndPortalOffset
                bw.BaseStream.Position = tmpPos;

                bw.Write((ushort) 0xCDCD); // separator

                bw.WriteArray(StaticMeshes, x => x.Write(bw, Engine.TR4));

                tmpPos = bw.BaseStream.Position;
                bw.BaseStream.Position = startPos + 172;
                bw.Write((uint) (tmpPos - start216)); // LayerOffset
                bw.BaseStream.Position = tmpPos;

                bw.WriteArray(Layers, x => x.Write(bw));

                tmpPos = bw.BaseStream.Position;
                bw.BaseStream.Position = startPos + 180;
                bw.Write((uint) (tmpPos - start216)); // PolyOffset
                bw.BaseStream.Position = startPos + 184;
                bw.Write((uint) (tmpPos - start216)); // PolyOffset2
                bw.BaseStream.Position = tmpPos;

                {
                    uint rectangleIndex = 0;
                    uint triangleIndex = 0;

                    foreach (var layer in Layers)
                    {
                        for (var j = 0; j < layer.NumRectangles; j++)
                        {
                            Rectangles[rectangleIndex].Write(bw, Engine.TR4);
                            rectangleIndex++;
                        }

                        for (var j = 0; j < layer.NumTriangles; j++)
                        {
                            Triangles[triangleIndex].Write(bw, Engine.TR4);
                            triangleIndex++;
                        }
                    }
                }

                tmpPos = bw.BaseStream.Position;
                bw.BaseStream.Position = startPos + 176;
                bw.Write((uint) (tmpPos - start216)); // VerticesOffset
                bw.BaseStream.Position = tmpPos;

                {
                    uint vertexIndex = 0;

                    foreach (var layer in Layers)
                    {
                        for (var j = 0; j < layer.NumVertices; j++)
                        {
                            Vertices[vertexIndex++].Write(bw, Engine.TR5);
                        }
                    }
                }

                var endPos = bw.BaseStream.Position;
                bw.BaseStream.Position = startPos - 4;
                bw.Write((uint) endPos - (uint) startPos); // room data size
                bw.BaseStream.Position = endPos;
            }
            else
            {
                bw.Write((int) Offset.X);
                bw.Write(-(int) Offset.Z);
                bw.Write(-(int) Y_Bottom);
                bw.Write(-(int) Y_Top);

                bw.Write((uint)0); // NumDataWords
                var dwStartPos = bw.BaseStream.Position;

                bw.Write((short)Vertices.Length);
                bw.WriteArray(Vertices, x => x.Write(bw, ver));

                bw.Write((short)Rectangles.Length);
                bw.WriteArray(Rectangles, x => x.Write(bw, Engine.TR1));

                bw.Write((short)Triangles.Length);
                bw.WriteArray(Triangles, x => x.Write(bw, Engine.TR1));

                if (Sprites == null) Sprites = new Sprite[0];

                bw.Write((short)Sprites.Length);
                bw.WriteArray(Sprites, x => x.Write(bw));

                var tmpPos = bw.BaseStream.Position;
                bw.BaseStream.Position = dwStartPos - 4;
                bw.Write((uint) (tmpPos - dwStartPos) / 2); // NumDataWords
                bw.BaseStream.Position = tmpPos;

                bw.Write((ushort) Portals.Length);
                bw.WriteArray(Portals, x => x.Write(bw));

                bw.Write(Num_Z_Sectors);
                bw.Write(Num_X_Sectors);

                bw.WriteArray(Sectors, x => x.Write(bw));

                if (ver == Engine.TR4)
                {
                    //bw.Write(RoomColor.ToUInt32()); todo
                }

                if (ver < Engine.TR3)
                {
                    bw.Write((short) (8191 - (Intensity1 >> 2))); // todo possible loss
                    if (ver >= Engine.TR2)
                        bw.Write((short) (8191 - (Intensity2 >> 2)));
                }
                else
                {
                    bw.Write(Intensity1);
                    bw.Write(Intensity2);
                }
                if (ver == Engine.TR2)
                {
                    bw.Write(LightMode);
                }

                bw.Write((ushort)Lights.Length);
                bw.WriteArray(Lights, x => x.Write(bw, ver));

                bw.Write((ushort) StaticMeshes.Length);
                bw.WriteArray(StaticMeshes, x => x.Write(bw, ver));

                bw.Write(AlternateRoom);

                var tmpFlags = Flags;
                if (tmpFlags.HasFlagUns(0x0002))
                {
                    tmpFlags = (ushort) ((tmpFlags | 0x0080) ^ 0x0002);
                        // Restore quicksand flag if it has been moved by Read()
                }

                bw.Write(tmpFlags);

                if (ver == Engine.TR3)
                {
                    bw.Write(WaterScheme);
                    bw.Write((byte) ReverbInfo);
                    bw.Write(Filler);
                }
                else if (ver == Engine.TR4)
                {
                    bw.Write(WaterScheme);
                    bw.Write((byte)ReverbInfo);
                    bw.Write(AlternateGroup);
                }
            }
        }
예제 #5
0
        public void Write(BinaryWriter bw, bool psx = false)
        {
            bw.Write((uint) GameVersion);
            bw.WriteStringASCII(CopyrightInfo, 256);
            bw.Write((ushort) 128); // gameflowSize

            bw.Write(FirstOption);
            bw.Write(TitleReplace);
            bw.Write(OnDeathDemoMode);
            bw.Write(OnDeathInGame);
            bw.Write(DemoTime);
            bw.Write(OnDemoInterrupt);
            bw.Write(OnDemoEnd);
            bw.Write(new byte[36]); // Unknown2
            bw.Write(NumLevels);
            bw.Write(NumChapterScreens);
            bw.Write(NumTitles);
            bw.Write(NumFMVs);
            bw.Write(NumCutscenes);
            bw.Write(NumDemoLevels);
            bw.Write(TitleSoundID);
            bw.Write(SingleLevel);
            bw.Write(new byte[32]); // Unknown3
            bw.Write((ushort) Flags);
            bw.Write(new byte[6]); // Unknown4
            bw.Write(XORbyte);
            bw.Write((byte) Language);
            bw.Write(SecretSoundID);
            bw.Write(new byte[4]); // Unknown5

            var xor = Flags.HasFlag(TOMBPCFlags.UseEncryption) ? XORbyte : (byte)0;
            bw.WriteStringArray(LevelDisplayNames, xor);
            bw.WriteStringArray(ChapterScreens, xor);
            bw.WriteStringArray(TitleFileNames, xor);
            bw.WriteStringArray(FMVFileNames, xor);
            bw.WriteStringArray(LevelFileNames, xor);
            bw.WriteStringArray(CutSceneFileNames, xor);

            var scrOffsets = new ushort[NumLevels + 1];
            ushort totalOffset = 0;
            for (var i = 0; i <= NumLevels; i++)
            {
                scrOffsets[i] = totalOffset;
                totalOffset += (ushort)(Script[i].Length * 2);
            }
            bw.WriteUInt16Array(scrOffsets);

            bw.Write((ushort)0);
            var nbPos = bw.BaseStream.Position;
            foreach (var a in Script.Resize(NumLevels + 1))
                bw.WriteUInt16Array(a);
            var tp = bw.BaseStream.Position;
            bw.BaseStream.Position = nbPos - 2;
            bw.Write((ushort)(tp - nbPos));
            bw.BaseStream.Position = tp;
            bw.WriteUInt16Array(DemoLevelIDs);

            if (psx)
            {
                bw.WriteArray(PSXFMVInfo.Resize(NumFMVs), x => x.Write(bw));
            }

            bw.Write((ushort) GameStrings1.Length);
            bw.WriteStringArray(GameStrings1, xor);
            bw.WriteStringArray(GameStrings2, xor);
            foreach (var puz in Puzzles.Resize(4))
                bw.WriteStringArray(puz.Resize(NumLevels), xor);
            foreach (var puz in Pickups.Resize(2))
                bw.WriteStringArray(puz.Resize(NumLevels), xor);
            foreach (var puz in Keys.Resize(4))
                bw.WriteStringArray(puz.Resize(NumLevels), xor);
        }
예제 #6
0
        private void Write_TR5()
        {
            if (EngineVersion != Engine.TR5)
            {
                ConvertRoomsToTR5();
            }

            writer.Write((uint) 0x00345254);

            writer.Write((ushort) Textures.Length);
            writer.Write((ushort) 0);
            writer.Write((ushort) 0);

            byte[] buf;
            using (var ms = new MemoryStream())
            {
                using (var bw = new BinaryWriter(ms))
                    bw.WriteArray(Textures, x => x.Write(bw));
                buf = ms.ToArray();
            }
            writer.Write((uint) buf.Length); // uncompSize
            var bufComp = Helper.Encompress(buf);
            writer.Write((uint) bufComp.Length); // compSize
            writer.Write(bufComp);

            using (var ms = new MemoryStream())
            {
                using (var bw = new BinaryWriter(ms))
                    bw.WriteArray(Texture16, x => x.Write(bw));
                buf = ms.ToArray();
            }
            writer.Write((uint) buf.Length); // uncompSize
            bufComp = Helper.Encompress(buf);
            writer.Write((uint) bufComp.Length); // compSize
            writer.Write(bufComp);

            using (var ms = new MemoryStream())
            {
                using (var bw = new BinaryWriter(ms))
                    bw.WriteArray(Textures.Skip(Textures.Length - 3).Take(3), x => x.Write(bw));
                buf = ms.ToArray();
            }
            writer.Write((uint) buf.Length); // uncompSize
            bufComp = Helper.Encompress(buf);
            writer.Write((uint) bufComp.Length); // compSize
            writer.Write(bufComp);


            writer.Write((ushort) LaraType);
            writer.Write((ushort) WeatherType);

            writer.Write(new byte[28]);

            var levelStartPos = writer.BaseStream.Position;

            writer.Write((uint)0); // uncompSize
            writer.Write((uint)0); // compSize

            writer.Write((uint) 0); // unused

            writer.Write((ushort) Rooms.Length);
            writer.WriteArray(Rooms, x => x.Write(writer, Engine.TR5));

            writer.Write((uint) FloorData.Length);
            writer.WriteUInt16Array(FloorData);

            WriteMeshData();

            writer.Write((uint) Animations.Length);
            writer.WriteArray(Animations, x => x.Write(writer, Engine.TR4));

            writer.Write((uint) StateChanges.Length);
            writer.WriteArray(StateChanges, x => x.Write(writer));

            writer.Write((uint) AnimDispatches.Length);
            writer.WriteArray(AnimDispatches, x => x.Write(writer));

            writer.Write((uint) AnimCommands.Length);
            writer.WriteInt16Array(AnimCommands);

            writer.Write((uint) MeshTreeData.Length);
            writer.WriteUInt32Array(MeshTreeData);

            WriteFrameMoveableData();

            writer.Write((uint) StaticMeshes.Length);
            writer.WriteArray(StaticMeshes, x => x.Write(writer));

            writer.Write((sbyte) 'S');
            writer.Write((sbyte) 'P');
            writer.Write((sbyte) 'R');
            writer.Write((sbyte) '\0');

            writer.Write((uint) SpriteTextures.Length);
            writer.WriteArray(SpriteTextures, x => x.Write(writer, Engine.TR4));

            writer.Write((uint) SpriteSequences.Length);
            writer.WriteArray(SpriteSequences, x => x.Write(writer));

            writer.Write((uint) Cameras.Length);
            writer.WriteArray(Cameras, x => x.Write(writer));

            writer.Write((uint) FlybyCameras.Length);
            writer.WriteArray(FlybyCameras, x => x.Write(writer));

            writer.Write((uint) SoundSources.Length);
            writer.WriteArray(SoundSources, x => x.Write(writer));

            writer.Write((uint) Boxes.Length);
            writer.WriteArray(Boxes, x => x.Write(writer, Engine.TR2));

            writer.Write((uint) Overlaps.Length);
            writer.WriteUInt16Array(Overlaps);

            writer.WriteArray(Zones, x => x.Write(writer, Engine.TR2));

            writer.Write((uint) AnimatedTextures.Length);
            writer.WriteUInt16Array(AnimatedTextures);

            writer.Write((byte) AnimatedTexturesUVCount);

            writer.Write((sbyte) 'T');
            writer.Write((sbyte) 'E');
            writer.Write((sbyte) 'X');
            writer.Write((sbyte) '\0');

            writer.Write((uint) ObjectTextures.Length);
            writer.WriteArray(ObjectTextures, x => x.Write(writer, Engine.TR5));

            writer.Write((uint) Items.Length);
            writer.WriteArray(Items, x => x.Write(writer, Engine.TR4));

            writer.Write((uint) AIObjects.Length);
            writer.WriteArray(AIObjects, x => x.Write(writer));

            writer.Write((ushort) DemoData.Length);
            writer.Write(DemoData);

            writer.WriteInt16Array(SoundMap.Resize(Constants.TR_AUDIO_MAP_SIZE_TR5));

            writer.Write((uint) SoundDetails.Length);
            writer.WriteArray(SoundDetails, x => x.Write(writer, Engine.TR3));

            writer.Write((uint) SampleIndices.Length);
            writer.WriteUInt32Array(SampleIndices);

            var levelEndPos = writer.BaseStream.Position;
            writer.BaseStream.Position = levelStartPos;
            var theSize = levelEndPos - levelStartPos;
            writer.Write((uint)theSize); // uncompSize
            writer.Write((uint)theSize); // compSize

            writer.BaseStream.Position = levelEndPos;

            writer.Write(new byte[6]);

            writer.Write((uint) SamplesCount);
            writer.Write(SamplesData);
        }
예제 #7
0
 void saveFileFunc(Stream stream)
 {
     var gStream = new DeflateStream(stream, CompressionLevel.Optimal);
     BinaryWriter writer = new BinaryWriter(gStream);
     uint width;
     uint height;
     uint startDozerBotX;
     uint startDozerBotY;
     byte[,] bytes = GetBytes(out width, out height, out startDozerBotX, out startDozerBotY);
     if (bytes == null)
         return;
     byte[] resultBytes = new byte[bytes.Length];
     Buffer.BlockCopy(bytes, 0, resultBytes, 0, resultBytes.Length);
     bytes = null;
     writer.Write(SilverBotAndGuy.Version.Current);
     writer.Write(width);
     writer.Write(height);
     writer.WriteArray(solutions.ToArray());
     bool silverBot = textBox1.Text.Contains('/');
     writer.Write(silverBot);
     if (silverBot)
     {
         string[] split = textBox1.Text.Replace("\r", "").Split('\n');
         int posOfSilverBotX = 0;
         int posOfSilverBotY = 0;
         while (posOfSilverBotY < height)
         {
             int indexOf = split[posOfSilverBotY].IndexOf('/');
             if (indexOf != -1)
             {
                 posOfSilverBotX = indexOf;
                 break;
             }
             posOfSilverBotY++;
         }
         writer.Write(posOfSilverBotX);
         writer.Write(posOfSilverBotY);
     }
     writer.Write(startDozerBotX);
     writer.Write(startDozerBotY);
     writer.Write(resultBytes, 0, resultBytes.Length);
     writer.Flush();
     writer.Close();
 }
예제 #8
0
 public void DrawWin (PlayerAvatar player)
 {
     if (outS != null)
     {
         byte[][] array = outS.GetBytes();
         BinaryWriter writer = new BinaryWriter(File.OpenWrite(outSolution));
         writer.WriteArray(array);
         writer.Flush();
         writer.Close();
     }
     if (File.Exists("Levels/" + (currentLevel + 1) +".sbalvl"))
         LoadNextLevel();
     else
     {
         won = true;
     }
 }
예제 #9
0
        private void SaveMccv(BinaryWriter writer, int basePosition, ref Mcnk header)
        {
            if (HasMccv == false)
            {
                header.Mccv = 0;
                header.Flags &= ~0x40u;
                return;
            }

            header.Flags |= 0x40;

            var colors = mShadingFloats.Select(v =>
            {
                uint b = (byte)Math.Max(Math.Min((v.Z / 2.0f) * 255.0f, 255), 0);
                uint g = (byte)Math.Max(Math.Min((v.Y / 2.0f) * 255.0f, 255), 0);
                uint r = (byte)Math.Max(Math.Min((v.X / 2.0f) * 255.0f, 255), 0);
                return 0x7F000000 | (b << 16) | (g << 8) | r;
            }).ToArray();

            header.Mccv = (int)writer.BaseStream.Position - basePosition;
            writer.Write(0x4D434356);
            writer.Write(145 * 4);
            writer.WriteArray(colors.ToArray());
        }
예제 #10
0
        private void SaveLayers(BinaryWriter writer, int basePosition, ref Mcnk header)
        {
            header.NumLayers = mLayers.Length;
            if(header.NumLayers == 0)
            {
                header.Mcly = 0;
                return;
            }

            header.Mcly = (int) writer.BaseStream.Position - basePosition;
            writer.Write(0x4D434C59);
            writer.Write(mLayers.Length * SizeCache<Mcly>.Size);
            writer.WriteArray(mLayers);
        }
예제 #11
0
        private void SaveNormals(BinaryWriter writer, int basePosition, ref Mcnk header)
        {
            header.Mcnr = (int)writer.BaseStream.Position - basePosition;

            var normals =
                Vertices.SelectMany(v => new[] { (sbyte)(v.Normal.X * -127.0f), (sbyte)(v.Normal.Y * -127.0f), (sbyte)(v.Normal.Z * 127.0f) });

            writer.Write(0x4D434E52);
            writer.Write(145 * 3);
            writer.WriteArray(normals.ToArray());
            writer.Write(mNormalExtra);
        }
예제 #12
0
 private void SaveHeights(BinaryWriter writer, int basePosition, ref Mcnk header)
 {
     header.Mcvt = (int) writer.BaseStream.Position - basePosition;
     var minPos = Vertices.Min(v => v.Position.Z);
     header.Position.Z = minPos;
     var heights = Vertices.Select(v => v.Position.Z - minPos);
     writer.Write(0x4D435654);
     writer.Write(145 * 4);
     writer.WriteArray(heights.ToArray());
 }
예제 #13
0
        public override void Save()
        {
            if (mWasChanged == false)
                return;

            var hasMccv = mChunks.Any(c => c != null && c.HasMccv);
            if(hasMccv)
            {
                var wdt = WorldFrame.Instance.MapManager.CurrentWdt;
                if((wdt.Flags & 2) == 0)
                {
                    wdt.Flags |= 2;
                    wdt.Save(WorldFrame.Instance.MapManager.Continent);
                }
            }

            using (var strm = FileManager.Instance.GetOutputStream(string.Format(@"World\Maps\{0}\{0}_{1}_{2}.adt", Continent, IndexX, IndexY)))
            {
                var writer = new BinaryWriter(strm);
                writer.Write(0x4D564552); // MVER
                writer.Write(4);
                writer.Write(18);
                writer.Write(0x4D484452);
                writer.Write(SizeCache<Mhdr>.Size);

                var headerStart = writer.BaseStream.Position;
                writer.Write(mHeader);
                var header = mHeader;

                var chunkInfos = mChunkOffsets.ToArray();
                writer.Write(0x4D43494E);
                writer.Write(256 * SizeCache<Mcin>.Size);
                var mcinStart = writer.BaseStream.Position;
                writer.WriteArray(chunkInfos);

                header.ofsMcin = (int)(mcinStart - 28);

                if (mDoodadDefs != null && mDoodadDefs.Length > 0)
                {
                    header.ofsMddf = (int)(writer.BaseStream.Position - 20);
                    writer.Write(0x4D444446);
                    writer.Write(mDoodadDefs.Length * SizeCache<Mddf>.Size);
                    writer.WriteArray(mDoodadDefs);
                }
                else
                    header.ofsMddf = 0;

                SaveChunk(0x4D544558, writer, out header.ofsMtex);
                SaveChunk(0x4D4D4458, writer, out header.ofsMmdx);
                SaveChunk(0x4D4D4944, writer, out header.ofsMmid);
                SaveChunk(0x4D574D4F, writer, out header.ofsMwmo);
                SaveChunk(0x4D574944, writer, out header.ofsMwid);
                SaveChunk(0x4D4F4446, writer, out header.ofsModf);
                SaveChunk(0x4D48324F, writer, out header.ofsMh2o);

                for (var i = 0; i < mChunks.Count; ++i)
                {
                    var startPos = writer.BaseStream.Position;
                    mChunks[i].SaveChunk(writer);
                    var endPos = writer.BaseStream.Position;
                    chunkInfos[i].OfsMcnk = (int)startPos;
                    chunkInfos[i].SizeMcnk = (int)(endPos - startPos);
                    //chunkInfos[i].Flags = chunkInfos[i].AsyncId = 0;
                }

                SaveChunk(0x4D545846, writer, out header.ofsMtxf);
                SaveChunk(0x4D46424F, writer, out header.ofsMfbo);

                writer.BaseStream.Position = headerStart;
                writer.Write(header);
                writer.BaseStream.Position = mcinStart;
                writer.WriteArray(chunkInfos);
            }
        }
예제 #14
0
 public void Write(BinaryWriter bw, Engine ver = Engine.Unknown)
 {
     bw.WriteArray(Colour, x => x.Write(bw, ver));
 }
예제 #15
0
 public void WriteBinaryData(System.IO.BinaryWriter writer)
 {
     writer.WriteArray(coeff);
 }
예제 #16
0
 public void Write(BinaryWriter bw)
 {
     bw.Write(AdjoiningRoom);
     Normal.Write16(bw);
     bw.WriteArray(Vertices, x => x.Write16(bw));
 }
예제 #17
0
        private void CreateEmptyWdt(BinaryWriter writer, string continent)
        {
            writer.Write(0x4D564552); // MVER
            writer.Write(4);
            writer.Write(18);
            writer.Write(0x4D484452);

            writer.Write(0x4D504844);
            writer.Write(32);
            writer.Write(Flags);
            writer.Write(0);
            writer.WriteArray(new[] {0, 0, 0, 0, 0, 0});

            writer.Write(0x4D41494E);
            writer.Write(4096 * 8);

            for (var i = 0; i < 64; ++i)
            {
                for(var j = 0; j < 64; ++j)
                {
                    if(FileManager.Instance.Provider.Exists(string.Format(@"World\Maps\{0}\{0}_{1}_{2}.adt", continent, j, i)))
                    {
                        writer.Write(1);
                        writer.Write(0);
                    }
                    else
                    {
                        writer.Write(0);
                        writer.Write(0);
                    }
                }
            }
        }