Example #1
0
        public void Write(Writer writer)
        {
            writer.Write(MAGIC);
            byte flags = 0;

            flags = (byte)SetBit(0, HasNormals, flags);
            flags = (byte)SetBit(1, HasTextures, flags);
            flags = (byte)SetBit(2, HasColours, flags);
            writer.Write(flags);

            writer.Write(FaceVerticiesCount);
            writer.Write((ushort)Frames[0].Vertices.Count);
            writer.Write((ushort)Frames.Count);

            if (HasTextures)
            {
                for (int i = 0; i < Frames[0].Vertices.Count; ++i)
                {
                    TexturePositions[i].Write(writer);
                }
            }

            if (HasColours)
            {
                for (int i = 0; i < Frames[0].Vertices.Count; ++i)
                {
                    Colours[i].Write(writer);
                }
            }

            writer.Write((ushort)Faces.Count);
            for (int i = 0; i < Faces.Count; ++i)
            {
                writer.Write(Faces[i]);
            }

            for (int i = 0; i < Frames.Count; ++i)
            {
                Frames[i].Write(writer, HasNormals);
            }
            writer.Close();
        }
Example #2
0
 public void write(Writer writer)
 {
     writer.Write(signature);
     using (var stream = new MemoryStream())
     {
         using (var cwriter = new Writer(stream))
         {
             for (int i = 0; i < TILES_COUNT; ++i)
             {
                 collisionMasks[0][i].write(cwriter);
             }
             for (int i = 0; i < TILES_COUNT; ++i)
             {
                 collisionMasks[1][i].write(cwriter);
             }
         }
         writer.writeCompressed(stream.ToArray());
     }
     writer.Close();
 }
Example #3
0
 // Write Compressed
 public void Write(Writer writer)
 {
     writer.Write(MAGIC);
     using (var stream = new MemoryStream())
     {
         using (var writerUncompressed = new BinaryWriter(stream))
         {
             for (int i = 0; i < TILES_COUNT; ++i)
             {
                 CollisionPath1[i].WriteUnc(writerUncompressed);
             }
             for (int i = 0; i < TILES_COUNT; ++i)
             {
                 CollisionPath2[i].WriteUnc(writerUncompressed);
             }
         }
         writer.WriteCompressed(stream.ToArray());
     }
     writer.Close();
 }
Example #4
0
        public void write(Writer writer)
        {
            using (var stream = new MemoryStream())
            {
                using (var cwriter = new Writer(stream))
                {
                    cwriter.Write(signature);

                    cwriter.Write(0x00); // data size (temp)

                    int loop = 0;
                    while (loop++ < 2)
                    {
                        if (loop == 2)
                        {
                            cwriter.Write(stream.ToArray().Length - 4); // data size (real)
                        }
                        cwriter.Write((ushort)rows.Count);
                        cwriter.Write((byte)columns.Count);

                        for (int i = 0; i < columns.Count; i++)
                        {
                            columns[i].write(cwriter);
                        }

                        for (int i = 0; i < rows.Count; i++)
                        {
                            rows[i].write(cwriter);
                        }

                        if (loop == 1)
                        {
                            cwriter.seek(4, SeekOrigin.Begin);
                        }
                    }
                }
                writer.writeCompressedRaw(stream.ToArray());
            }

            writer.Close();
        }
Example #5
0
        public void write(Writer writer)
        {
            writer.Write(visible);

            writer.writeRSDKString(name);

            writer.Write((byte)type);
            writer.Write(drawOrder);

            writer.Write(width);
            writer.Write(height);

            writer.Write(parallaxFactor);
            writer.Write(scrollSpeed);

            writer.Write((ushort)scrollInfo.Count);
            foreach (ScrollInfo info in scrollInfo)
            {
                info.write(writer);
            }

            writer.writeCompressed(lineScroll);

            using (MemoryStream cmem = new MemoryStream())
            {
                using (Writer cwriter = new Writer(cmem))
                {
                    for (int y = 0; y < height; ++y)
                    {
                        for (int x = 0; x < width; ++x)
                        {
                            cwriter.Write(layout[y][x]);
                        }
                    }
                    cwriter.Close();
                    writer.writeCompressed(cmem.ToArray());
                }
            }
        }
Example #6
0
        public Replay(Reader reader)
        {
            Reader creader = reader.GetCompressedStreamRaw();

            //creader.BaseStream.Position = 0x84;

            byte[] data  = new byte[creader.BaseStream.Length];
            int[]  data2 = new int[creader.BaseStream.Length / 4];

            for (int i = 0; i < creader.BaseStream.Length; i++)
            {
                data[i] = creader.ReadByte();
            }

            creader.BaseStream.Position = 0;
            for (int i = 0; i < creader.BaseStream.Length / 4; i++)
            {
                data2[i] = creader.ReadInt32();
            }

            creader.Close();

            //data[0]: Header
            //data[1]: Header
            //data[2]: Packed Flag
            //data[3]: Header
            //data[5]: EntryCount

            //data[11]: ???

            //Entries Start: 14/0xE
            //Entry Size: 28/0x1C (bytes?)

            Writer writer = new Writer("Replay.bin");

            writer.Write(data);
            writer.Close();
        }
        internal void Write(Writer writer)
        {
            writer.Write(IgnoredByte);

            writer.WriteRSDKString(Name);

            writer.Write(UnknownByte1);
            writer.Write(UnknownByte2);

            writer.Write(Width);
            writer.Write(Height);

            writer.Write(UnknownWord1);
            writer.Write(UnknownWord2);

            writer.Write((ushort)ScrollingInfo.Count);
            foreach (ScrollInfo info in ScrollingInfo)
            {
                info.Write(writer);
            }

            writer.WriteCompressed(ScrollIndexes);

            using (MemoryStream cmem = new MemoryStream())
                using (Writer cwriter = new Writer(cmem))
                {
                    for (int i = 0; i < Height; ++i)
                    {
                        for (int j = 0; j < Width; ++j)
                        {
                            cwriter.Write(Tiles[i][j]);
                        }
                    }
                    cwriter.Close();
                    writer.WriteCompressed(cmem.ToArray());
                }
        }
Example #8
0
        public void Write(Writer writer)
        {
            writer.Write(MAGIC);
            writer.Write(TotalFrameCount);

            writer.Write((byte)SpriteSheets.Count);
            for (int i = 0; i < SpriteSheets.Count; ++i)
            {
                writer.WriteRSDKString(SpriteSheets[i] + '\0');
            }

            writer.Write((byte)CollisionBoxes.Count);
            for (int i = 0; i < CollisionBoxes.Count; ++i)
            {
                writer.WriteRSDKString(CollisionBoxes[i] + '\0');
            }

            writer.Write((ushort)Animations.Count);
            for (int i = 0; i < Animations.Count; ++i)
            {
                Animations[i].Write(writer);
            }
            writer.Close();
        }
Example #9
0
        public void Write(Writer writer)
        {
            writer.Write(MAGIC);
            int MemPos = 0;

            for (uint DataPos = 0; DataPos < Data.Length;)
            {
                uint offset        = DataPos;
                byte FirstDataType = 0;
                byte DataTypeBuf   = 0;
                byte DataType      = 0;
                uint DataSize      = 0;

                if (Data[offset] >= 0)
                {
                    if (Data[offset] <= byte.MaxValue)
                    {
                        FirstDataType = DataTypeBuf = (int)AttributeTypes.UINT8;
                    }
                    if (Data[offset] > byte.MaxValue && Data[offset] <= ushort.MaxValue)
                    {
                        FirstDataType = DataTypeBuf = (int)AttributeTypes.UINT16;
                    }
                    if (Data[offset] > ushort.MaxValue)
                    {
                        FirstDataType = DataTypeBuf = (int)AttributeTypes.UINT32;
                    }
                }
                else
                {
                    if (Data[offset] > sbyte.MinValue)
                    {
                        FirstDataType = DataTypeBuf = (int)AttributeTypes.INT8;
                    }
                    if (Data[offset] <= sbyte.MinValue && Data[offset] >= short.MinValue)
                    {
                        FirstDataType = DataTypeBuf = (int)AttributeTypes.INT16;
                    }
                    if (Data[offset] <= short.MinValue && Data[offset] >= int.MinValue)
                    {
                        FirstDataType = DataTypeBuf = (int)AttributeTypes.INT32;
                    }
                }
                offset++;

                while (FirstDataType == DataTypeBuf && offset < Data.Length)
                {
                    if (Data[offset] >= 0)
                    {
                        if (Data[offset] <= byte.MaxValue)
                        {
                            DataTypeBuf = (int)AttributeTypes.UINT8;
                        }
                        if (Data[offset] > byte.MaxValue && Data[offset] <= ushort.MaxValue)
                        {
                            DataTypeBuf = (int)AttributeTypes.UINT16;
                        }
                        if (Data[offset] > ushort.MaxValue)
                        {
                            DataTypeBuf = (int)AttributeTypes.UINT32;
                        }
                        if (FirstDataType == DataTypeBuf)
                        {
                            offset++;
                        }
                        else
                        {
                            DataType = FirstDataType;
                        }
                    }
                    else
                    {
                        if (Data[offset] > sbyte.MinValue)
                        {
                            DataTypeBuf = (int)AttributeTypes.INT8;
                        }
                        if (Data[offset] <= sbyte.MinValue && Data[offset] >= short.MinValue)
                        {
                            DataTypeBuf = (int)AttributeTypes.INT16;
                        }
                        if (Data[offset] <= short.MinValue && Data[offset] >= int.MinValue)
                        {
                            DataTypeBuf = (int)AttributeTypes.INT32;
                        }
                        if (FirstDataType == DataTypeBuf)
                        {
                            offset++;
                        }
                        else
                        {
                            DataType = FirstDataType;
                        }
                    }
                }

                if (offset == Data.Length)
                {
                    DataType = FirstDataType;
                }

                FirstDataType = DataTypeBuf;

                DataSize = offset - DataPos;
                //DataPos = offset;
                DataType |= 0x80;

                writer.Write(DataType);
                writer.Write(MemPos);

                if ((DataType & 0x80) != 0)
                {
                    writer.Write(DataSize);

                    switch (DataType & 0x7F)
                    {
                    //INT8
                    case (int)AttributeTypes.UINT8:
                        for (int i = 0; i < DataSize; i++)
                        {
                            writer.Write((byte)Data[DataPos++]);
                        }
                        break;

                    case (int)AttributeTypes.INT8:
                        for (int i = 0; i < DataSize; i++)
                        {
                            writer.Write((sbyte)Data[DataPos++]);
                        }
                        break;

                    //IN16
                    case (int)AttributeTypes.UINT16:
                        for (int i = 0; i < DataSize; i++)
                        {
                            writer.Write((ushort)Data[DataPos++]);
                        }
                        break;

                    case (int)AttributeTypes.INT16:
                        for (int i = 0; i < DataSize; i++)
                        {
                            writer.Write((short)Data[DataPos++]);
                        }
                        break;

                    //INT32
                    case (int)AttributeTypes.UINT32:
                        for (int i = 0; i < DataSize; i++)
                        {
                            writer.Write((uint)Data[DataPos++]);
                        }
                        break;

                    case (int)AttributeTypes.INT32:
                        for (int i = 0; i < DataSize; i++)
                        {
                            writer.Write((int)Data[DataPos++]);
                        }
                        break;

                    case (int)AttributeTypes.ENUM:
                        for (int i = 0; i < DataSize; i++)
                        {
                            writer.Write((uint)Data[DataPos++]);
                        }
                        break;
                    }
                }
            }

            writer.Close();
        }
Example #10
0
        public void WriteAsSTLBinary(Writer writer)
        {
            Debugger.Launch();
            byte[] junk = Encoding.ASCII.GetBytes("Kimi no sei kimi no sei kimi no sei de watashi Oh Okubyou de kakkou tsukanai kimi no sei da yo");
            writer.Write(junk, 0, 0x50);

            writer.Write((int)(Faces.Count / FaceVerticiesCount));
            // Triangle

            var vertices = new Frame.Vertex[FaceVerticiesCount];

            for (int v = 0; v < Faces.Count; v += FaceVerticiesCount)
            {
                for (int ii = 0; ii < FaceVerticiesCount; ++ii)
                {
                    vertices[ii] = Frames[0].Vertices[Faces[v + ii]];
                }

                // Normal
                writer.Write(vertices[0].normal.x);
                writer.Write(vertices[0].normal.y);
                writer.Write(vertices[0].normal.z);

                // Vector 1
                writer.Write(vertices[0].x);
                writer.Write(vertices[0].z);
                writer.Write(vertices[0].y);
                // Vector 2
                writer.Write(vertices[1].x);
                writer.Write(vertices[1].z);
                writer.Write(vertices[1].y);
                // Vector 3
                writer.Write(vertices[2].x);
                writer.Write(vertices[2].z);
                writer.Write(vertices[2].y);

                // Attribute
                if (HasColours)
                {
                    int    colour = Faces[v];
                    ushort attb   = (ushort)(ToRGB555(Colours[colour].r, Colours[colour].g, Colours[colour].b));
                    writer.Write(attb);
                }
                else
                {
                    writer.Write((short)0);
                }

                if (FaceVerticiesCount == 4)
                {
                    // Normal
                    writer.Write(vertices[0].normal.x);
                    writer.Write(vertices[0].normal.y);
                    writer.Write(vertices[0].normal.z);

                    // Vector 1
                    writer.Write(vertices[0].x);
                    writer.Write(vertices[0].z);
                    writer.Write(vertices[0].y);
                    // Vector 2
                    writer.Write(vertices[2].x);
                    writer.Write(vertices[2].z);
                    writer.Write(vertices[2].y);
                    // Vector 3
                    writer.Write(vertices[3].x);
                    writer.Write(vertices[3].z);
                    writer.Write(vertices[3].y);

                    // Attribute
                    if (HasColours)
                    {
                        int    colour = Faces[v];
                        ushort attb   = (ushort)(ToRGB555(Colours[colour].r, Colours[colour].g, Colours[colour].b));
                        writer.Write(attb);
                    }
                    else
                    {
                        writer.Write((short)0);
                    }
                }
            }

            writer.Close();
        }
Example #11
0
        public void Write(Writer writer)
        {
            writer.Write(MAGIC);

            for (DataPos = 0; DataPos < Data.Length;)
            {
                byte Unknown1 = 0;
                writer.Write(Unknown1);
                writer.Write(Data[DataPos++]);

                if ((Unknown1 & 0x80) != 0)
                {
                    uint Unknown3 = 0;
                    writer.Write(Unknown3);

                    int Variable1 = Unknown1 & 0x7F;

                    switch (Variable1)
                    {
                    //INT8
                    case 0:
                        for (int i = 0; i < Unknown3; i++)
                        {
                            writer.Write((byte)Data[DataPos++]);
                        }
                        break;

                    case 3:
                        for (int i = 0; i < Unknown3; i++)
                        {
                            writer.Write((byte)Data[DataPos++]);
                        }
                        break;

                    //IN16
                    case 1:
                        for (int i = 0; i < Unknown3; i++)
                        {
                            writer.Write((ushort)Data[DataPos++]);
                        }
                        break;

                    case 4:
                        for (int i = 0; i < Unknown3; i++)
                        {
                            writer.Write((ushort)Data[DataPos++]);
                        }
                        break;

                    //INT32
                    case 2:
                        for (int i = 0; i < Unknown3; i++)
                        {
                            writer.Write(Data[DataPos++]);
                        }
                        break;

                    case 5:
                        for (int i = 0; i < Unknown3; i++)
                        {
                            writer.Write(Data[DataPos++]);
                        }
                        break;

                    case 6:
                        for (int i = 0; i < Unknown3; i++)
                        {
                            writer.Write(Data[DataPos++]);
                        }
                        break;
                    }
                }
            }

            writer.Close();
        }
Example #12
0
        public void write(Writer writer)
        {
            using (var stream = new MemoryStream())
            {
                using (var cwriter = new Writer(stream))
                {
                    int    bufferSize       = 0;
                    byte[] frameBuffer      = new byte[1];
                    float  averageSize      = 0;
                    int    packedFrameCount = 0;

                    using (var frameStream = new MemoryStream())
                    {
                        using (var fwriter = new Writer(frameStream))
                        {
                            foreach (ReplayEntry frame in frames)
                            {
                                int frameSize = frame.pack(fwriter, isPacked);
                                bufferSize += frameSize;

                                if (frames.Count > 1)
                                {
                                    uint  frameCount = (uint)frames.Count;
                                    float avg        = averageSize;
                                    float sizef      = frameSize;
                                    averageSize = ((avg * packedFrameCount) + sizef) / (packedFrameCount + 1);
                                }
                                else
                                {
                                    averageSize = frameSize;
                                }
                                packedFrameCount++;
                            }
                        }
                        frameBuffer = frameStream.ToArray();
                    }

                    if (!isPacked)
                    {
                        bufferSize = 28 * (frames.Count + 2);
                    }

                    cwriter.Write(signature);
                    cwriter.Write(gameVer);
                    cwriter.writeBool32(isPacked ? true : false);
                    cwriter.writeBool32(frames.Count >= 1 ? true : false);
                    cwriter.Write(frames.Count);
                    cwriter.Write(startingFrame);
                    cwriter.Write(zoneID);
                    cwriter.Write(act);
                    cwriter.Write(characterID);
                    cwriter.writeBool32(isPlusLayout ? true : false);
                    cwriter.Write(oscillation);
                    cwriter.Write(bufferSize);
                    cwriter.Write(averageSize);
                    cwriter.Write(unknown);

                    cwriter.Write(frameBuffer);
                }
                writer.writeCompressedRaw(stream.ToArray());
            }

            writer.Close();
        }
Example #13
0
        public void write(Writer writer, bool skipHeader = false, bool useLocal = false)
        {
            #region Header
            // [GIF HEADER]
            if (!skipHeader)
            {
                writer.Write("GIF".ToCharArray()); // File type
                writer.Write("89a".ToCharArray()); // File Version

                writer.Write(width);
                writer.Write(height);

                if (useLocal)
                {
                    writer.Write((byte)((1 << 7) | (6 << 4) | 6)); // 1 == hasColours, 6 == paletteSize of 128, 6 == 7bpp
                }
                else
                {
                    writer.Write((byte)((1 << 7) | (7 << 4) | 7)); // 1 == hasColours, 7 == paletteSize of 256, 7 == 8bpp
                }
                writer.Write((byte)0);
                writer.Write((byte)0);
            }

            // [GLOBAL PALETTE]
            for (int c = 0; c < (useLocal ? 0x80 : 0x100); ++c)
            {
                writer.Write(palette[c].R);
                writer.Write(palette[c].G);
                writer.Write(palette[c].B);
            }
            #endregion

            #region Extension Blocks
            // [EXTENSION BLOCKS]
            #endregion

            #region Image Descriptor Block
            // [IMAGE DESCRIPTOR HEADER]
            writer.Write(',');

            writer.Write((ushort)0);
            writer.Write((ushort)0);
            writer.Write((ushort)width);
            writer.Write((ushort)height);
            if (useLocal)
            {
                writer.Write((byte)((1 << 7) | (0 << 6) | 6)); // 1 == useLocal, 0 == no interlacing, 6 == 7bpp
            }
            else
            {
                writer.Write((byte)((0 << 7) | (0 << 6) | 0)); // 0 == noLocal, 0 == no interlacing, no local palette, so we dont care
            }
            // [LOCAL PALETTE]
            if (useLocal)
            {
                for (int c = 0x80; c < 0x100; ++c)
                {
                    writer.Write(palette[c].R);
                    writer.Write(palette[c].G);
                    writer.Write(palette[c].B);
                }
            }

            // [IMAGE DATA]
            writePictureData(width, height, false, useLocal ? (byte)7 : (byte)8, writer);

            // [BLOCK END MARKER]
            writer.Write(';'); // ';' used for image descriptor, 0 would be used for other blocks
            #endregion

            writer.Close();
        }