Example #1
0
 void SendExtEntry(string name, int version)
 {
     byte[] buffer = new byte[69];
     buffer[0] = Opcode.CpeExtEntry;
     NetUtils.WriteAscii(name, buffer, 1);
     NetUtils.WriteI32(version, buffer, 65);
     SendRaw(buffer, true);
 }
Example #2
0
 public static byte[] ExtEntry(string name, int version)
 {
     byte[] buffer = new byte[69];
     buffer[0] = Opcode.CpeExtEntry;
     NetUtils.WriteAscii(name, buffer, 1);
     NetUtils.WriteI32(version, buffer, 65);
     return(buffer);
 }
Example #3
0
 public static byte[] EnvMapProperty(EnvProp prop, int value)
 {
     byte[] buffer = new byte[6];
     buffer[0] = Opcode.CpeSetMapEnvProperty;
     buffer[1] = (byte)prop;
     NetUtils.WriteI32(value, buffer, 2);
     return(buffer);
 }
Example #4
0
 void SendTextHotKey(string label, string command, int keycode, byte mods)
 {
     byte[] buffer = new byte[134];
     buffer[0] = Opcode.CpeSetTextHotkey;
     NetUtils.WriteAscii(label, buffer, 1);
     NetUtils.WriteAscii(command, buffer, 65);
     NetUtils.WriteI32(keycode, buffer, 129);
     buffer[133] = mods;
     SendRaw(buffer);
 }
Example #5
0
 public static byte[] TextHotKey(string label, string input, int keycode, byte mods)
 {
     byte[] buffer = new byte[134];
     buffer[0] = Opcode.CpeSetTextHotkey;
     NetUtils.WriteAscii(label, buffer, 1);
     NetUtils.WriteAscii(input, buffer, 65);
     NetUtils.WriteI32(keycode, buffer, 129);
     buffer[133] = mods;
     return(buffer);
 }
Example #6
0
        public unsafe static void WriteF32(float value, byte[] buffer, int i)
        {
            int num = *(int *)&value;

            NetUtils.WriteI32(num, buffer, i);
        }
Example #7
0
        unsafe byte[] CompressRawMap(out int usedLength)
        {
            const int bufferSize = 64 * 1024;

            byte[]       buffer = new byte[bufferSize];
            MemoryStream temp   = new MemoryStream();
            int          bIndex = 0;

            // Store locally instead of performing func call for every block in map
            byte *conv    = stackalloc byte[256];
            byte *convCPE = stackalloc byte[256];

            for (int i = 0; i < 256; i++)
            {
                conv[i] = Block.Convert((byte)i);
            }
            if (!hasCustomBlocks)
            {
                for (int i = 0; i < 256; i++)
                {
                    convCPE[i] = Block.ConvertCPE((byte)i);
                }
            }

            using (GZipStream compressor = new GZipStream(temp, CompressionMode.Compress, true)) {
                NetUtils.WriteI32(level.blocks.Length, buffer, 0);
                compressor.Write(buffer, 0, sizeof(int));

                // compress the map data in 64 kb chunks
                if (hasCustomBlocks)
                {
                    for (int i = 0; i < level.blocks.Length; ++i)
                    {
                        byte block = level.blocks[i];
                        if (block == Block.custom_block)
                        {
                            buffer[bIndex] = hasBlockDefs ? level.GetExtTile(i) : level.GetFallbackExtTile(i);
                        }
                        else
                        {
                            buffer[bIndex] = conv[block];
                        }

                        bIndex++;
                        if (bIndex == bufferSize)
                        {
                            compressor.Write(buffer, 0, bufferSize); bIndex = 0;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < level.blocks.Length; ++i)
                    {
                        byte block = level.blocks[i];
                        if (block == Block.custom_block)
                        {
                            block          = hasBlockDefs ? level.GetExtTile(i) : level.GetFallbackExtTile(i);
                            buffer[bIndex] = convCPE[block];
                        }
                        else
                        {
                            buffer[bIndex] = convCPE[conv[block]];
                        }

                        bIndex++;
                        if (bIndex == bufferSize)
                        {
                            compressor.Write(buffer, 0, bufferSize); bIndex = 0;
                        }
                    }
                }
                if (bIndex > 0)
                {
                    compressor.Write(buffer, 0, bIndex);
                }
            }
            usedLength = (int)temp.Length;
            return(temp.GetBuffer());
        }
Example #8
0
        public unsafe static void CompressMap(Player p, LevelChunkStream dst)
        {
            const int bufferSize = 64 * 1024;

            byte[] buffer = new byte[bufferSize];
            int    bIndex = 0;

            // Store on stack instead of performing function call for every block in map
            byte *conv    = stackalloc byte[256];
            byte *convCPE = stackalloc byte[256];

            for (int i = 0; i < 256; i++)
            {
                conv[i] = Block.Convert((byte)i);
            }

            if (!p.hasCustomBlocks)
            {
                for (int i = 0; i < 256; i++)
                {
                    convCPE[i] = Block.ConvertCPE((byte)i);
                    conv[i]    = Block.ConvertCPE(conv[i]);
                }
            }

            Level lvl          = p.level;
            bool  hasBlockDefs = p.hasBlockDefs;

            using (GZipStream gs = new GZipStream(dst, CompressionMode.Compress, true)) {
                byte[] blocks = lvl.blocks;
                NetUtils.WriteI32(blocks.Length, buffer, 0);
                gs.Write(buffer, 0, sizeof(int));
                dst.length = blocks.Length;

                // compress the map data in 64 kb chunks
                if (p.hasCustomBlocks)
                {
                    for (int i = 0; i < blocks.Length; ++i)
                    {
                        byte block = blocks[i];
                        if (block == Block.custom_block)
                        {
                            buffer[bIndex] = hasBlockDefs ? lvl.GetExtTile(i) : lvl.GetFallbackExtTile(i);
                        }
                        else
                        {
                            buffer[bIndex] = conv[block];
                        }

                        bIndex++;
                        if (bIndex == bufferSize)
                        {
                            dst.position = i;
                            gs.Write(buffer, 0, bufferSize); bIndex = 0;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < blocks.Length; ++i)
                    {
                        byte block = blocks[i];
                        if (block == Block.custom_block)
                        {
                            block          = hasBlockDefs ? lvl.GetExtTile(i) : lvl.GetFallbackExtTile(i);
                            buffer[bIndex] = convCPE[block];
                        }
                        else
                        {
                            buffer[bIndex] = conv[block];
                        }

                        bIndex++;
                        if (bIndex == bufferSize)
                        {
                            dst.position = i;
                            gs.Write(buffer, 0, bufferSize); bIndex = 0;
                        }
                    }
                }
                if (bIndex > 0)
                {
                    gs.Write(buffer, 0, bIndex);
                }
            }
        }