WriteByte() public method

public WriteByte ( byte v ) : void
v byte
return void
Example #1
0
 public static void SendPacket(this AsyncConnection con, IServerPacket pkt)
 {
     byte opcode = OpcodeManager.Instance.GetOpcode(pkt.GetType().Name);
     uint packetid = OpcodeManager.Instance.GetPacketID(pkt.GetType().Name);
     if (packetid == 0)
     {
         TORLog.Error("ERROR: No PacketID defined for " + pkt.GetType().Name);
         return;
     }
     ByteBuffer packet = new ByteBuffer(ByteOrder.LittleEndian);
     packet.WriteByte(opcode);
     packet.WriteInt(0); // Length
     packet.WriteByte(0); // ChkByte
     packet.WriteUInt(packetid);
     pkt.WritePacket(con, packet);
     con.SendTORPacket(packet);
     TORLog.Network("PktSend @ " + con.GetHashCode() + " >> " + pkt.GetType().Name);
 }
Example #2
0
        public static byte[] StringToByteArray(string[] args, int start = 1)
        {
            using (ByteBuffer buffer = new ByteBuffer())
            {
                for (int i = start; i < args.Length; i++)
                {
                    buffer.WriteByte(byte.Parse(args[i], System.Globalization.NumberStyles.HexNumber));
                }

                buffer.Flip();
                return(buffer.GetContent());
            }
        }
        public byte[] ToByteArray()
        {
            using (ByteBuffer buffer = new ByteBuffer())
            {
                buffer.WriteByte();
                buffer.WriteByte(1);
                buffer.WriteShort((short)this.Count);

                List <Skill> cooldownSkills = new List <Skill>();

                foreach (Skill loopSkill in this)
                {
                    buffer.WriteInt(loopSkill.MapleID);
                    buffer.WriteInt(loopSkill.CurrentLevel);
                    buffer.WriteLong((long)ExpirationTime.DefaultTime);

                    if (loopSkill.IsFromFourthJob)
                    {
                        buffer.WriteInt(loopSkill.MaxLevel);
                    }

                    if (loopSkill.IsCoolingDown)
                    {
                        cooldownSkills.Add(loopSkill);
                    }
                }

                buffer.WriteShort((short)cooldownSkills.Count);

                foreach (Skill loopCooldown in cooldownSkills)
                {
                    buffer.WriteInt(loopCooldown.MapleID);
                    buffer.WriteShort((short)loopCooldown.RemainingCooldownSeconds);
                }

                buffer.Flip();
                return(buffer.GetContent());
            }
        }
        /// <summary>
        /// Sends a message to the player
        /// </summary>
        public void SendMessage(string message)
        {
            ByteBuffer buffer = new ByteBuffer(Opcodes.Message);

            foreach (string line in LineWrapper.WrapLines(message))
            {
                buffer.SetPosition(1);
                buffer.WriteByte(0);
                buffer.WriteString(line, UseCP437 ? Server.CP437 : Encoding.ASCII);
                SendRaw(buffer.Data);
                buffer.SetPosition(0);
            }
        }
Example #5
0
        void PatchRawSmallSection(ByteBuffer buffer, MetadataBuilder metadata)
        {
            var length = ReadByte();

            buffer.WriteByte(length);
            Advance(2);

            buffer.WriteUInt16(0);

            var count = length / 12;

            PatchRawExceptionHandlers(buffer, metadata, count, false);
        }
Example #6
0
    void _zjfk()
    {
        ConfirmUtil.TryToDispear();
        DealBody.Order order  = orders[selectIndex];
        ByteBuffer     buffer = ByteBuffer.Allocate(1024);

        buffer.skip(4);
        buffer.WriteString("AdminDealOrderUpdate");
        buffer.WriteLong(order.item.id);
        buffer.WriteLong(order.id);
        buffer.WriteByte((byte)5);
        NetUtil.getInstance.SendMessage(buffer);
    }
Example #7
0
    public void doAddAddress()
    {
        Transform  container = needshow[0].transform.FindChild("address-body").FindChild("add");
        UIInput    input     = container.FindChild("inputer").GetComponent <UIInput>();
        ByteBuffer buffer    = ByteBuffer.Allocate(1024);

        buffer.skip(4);
        buffer.WriteString("AddressChange");
        buffer.WriteByte(0);
        buffer.WriteLong(MainData.instance.user.id);//编号
        buffer.WriteString(input.value);
        NetUtil.getInstance.SendMessage(buffer);
    }
        public void WriteByteReadByte()
        {
            var buffer = new ByteBuffer(16);

            for (var i = 0; i < InputBytes.Length; i++)
            {
                buffer.WriteByte(InputBytes[i]);
            }
            for (var i = 0; i < InputBytes.Length; i++)
            {
                Assert.AreEqual(buffer.ReadByte(i), InputBytes[i]);
            }
        }
Example #9
0
    void _fk()
    {
        ConfirmUtil.TryToDispear();
        ByteBuffer buffer = ByteBuffer.Allocate(1024);

        buffer.skip(4);
        buffer.WriteString("DealOrderUpdate");
        buffer.WriteLong(order.dealId);
        buffer.WriteLong(order.id);
        buffer.WriteLong(MainData.instance.user.id);
        buffer.WriteByte(1);
        NetUtil.getInstance.SendMessage(buffer);
    }
Example #10
0
        public static byte[] write()
        {
            byte[] temp = init();
            ByteBuffer buff = new ByteBuffer();
            buff.WriteD(temp.Length + 4);
            for (int i = 0; i < temp.Length - 1; i++)
            {
                buff.WriteByte(temp[i]);
            }
            buff.Resize(temp.Length + 4);
            size = buff.Length();

            return buff.Get_ByteArray();
        }
Example #11
0
        public byte[] ToByteArray()
        {
            using (ByteBuffer buffer = new ByteBuffer())
            {
                if (this.GetSPType(this.Parent) == ExtendedSPType.Regular)
                {
                    buffer.WriteShort(this.Parent.AvailableSP);
                }
                else
                {
                    buffer.WriteByte((byte)this.Count);

                    foreach (KeyValuePair <byte, byte> advance in this)
                    {
                        buffer.WriteByte(advance.Key);
                        buffer.WriteByte(advance.Value);
                    }
                }

                buffer.Flip();
                return(buffer.GetContent());
            }
        }
Example #12
0
        public override byte[] ToByteArray()
        {
            using (ByteBuffer writer = new ByteBuffer())
            {
                writer.WriteShort(this.Position.X);
                writer.WriteShort(this.Position.Y);
                writer.WriteShort(this.Wobble.X);
                writer.WriteShort(this.Wobble.Y);
                writer.WriteByte(this.NewStance);

                writer.Flip();
                return(writer.GetContent());
            }
        }
Example #13
0
        public void PeekTest()
        {
            ByteBuffer buffer = new ByteBuffer(100);

            for (byte i = 0; i < 100; i++)
            {
                buffer.WriteByte(i);
            }

            for (byte i = 0; i < 100; i++)
            {
                Assert.AreEqual(i, buffer.Peek(i));
            }
        }
Example #14
0
 private void NotifyNewUser()
 {
     using (var response = new ByteBuffer())
     {
         var user = new User {
             Identity = this.Identity, Name = this.Name
         };
         response.WriteByte((byte)Protocol.NewUser)
         .WriteByteArray(serializer.Serialize(user));
         foreach (var client in MainForm.Clients.Where(item => item.Key != this.Identity))
         {
             client.Value.Socket.Send(response.ToArray());
         }
     }
 }
Example #15
0
        /// <summary>
        /// 二进制消息
        /// </summary>
        void OnBinaryMessage(ClientSession session, ByteBuffer buffer)
        {
            string str = buffer.ReadString();

            session.uid = buffer.ReadInt();

            ByteBuffer newBuffer = new ByteBuffer();

            newBuffer.WriteByte((byte)ProtocalType.BINARY);
            newBuffer.WriteString(str);
            SocketUtil.SendMessage(session, Protocal.Login, newBuffer);

            UserUtil.Add(session.uid, session);
            Console.WriteLine("OnBinaryMessage--->>>" + str + session.uid);
        }
Example #16
0
        /// <summary>
        /// pbc消息
        /// </summary>
        void OnPbcMessage(ClientSession session, ByteBuffer buffer)
        {
            tutorial.Person request = ProtoUtil.GetMessage <tutorial.Person>(buffer);
            Console.WriteLine("OnPbcMessage id=>>" + request.id + " name:>>>" + request.name);
            buffer.Close(); buffer = null;

            byte[] data = ProtoUtil.SetMessage <tutorial.Person>(request);

            ByteBuffer newBuffer = new ByteBuffer();

            newBuffer.WriteByte((byte)ProtocalType.PBC);
            newBuffer.WriteBytes(data); //添加数据

            SocketUtil.SendMessage(session, Protocal.Login, newBuffer);
        }
Example #17
0
        private static void WriteVarInt(ByteBuffer data, int v)
        {
            var n     = 0;
            var array = new byte[4];

            do
            {
                array[n++] = (byte)((v & 0x7F) & 0xFF);
                v        >>= 7;
            } while (v > 0);

            while (n > 0)
            {
                n--;
                if (n > 0)
                {
                    data.WriteByte((byte)((array[n] | 0x80) & 0xFF));
                }
                else
                {
                    data.WriteByte(array[n]);
                }
            }
        }
Example #18
0
 static int WriteByte(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         ByteBuffer obj  = (ByteBuffer)ToLua.CheckObject(L, 1, typeof(ByteBuffer));
         byte       arg0 = (byte)LuaDLL.luaL_checknumber(L, 2);
         obj.WriteByte(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #19
0
    public static ByteBuffer BuildMessageBody(byte[] arrBody, int nMessageID, int nTimeStamp)
    {
        ByteBuffer pBuffer = new ByteBuffer(arrBody.Length + MsgBase.META_DATA_LENGTH);

        ushort sCheckCode     = NetworkStub.GetCheckCode(arrBody);
        byte   byteEncodeType = MsgBase.MESSAGE_ENCODE_TYPE_JSON;

        pBuffer.WriteByte(byteEncodeType);
        pBuffer.WriteInt(nMessageID);
        pBuffer.WriteUShort((ushort)sCheckCode);
        pBuffer.WriteInt(nTimeStamp);
        pBuffer.WriteBytes(arrBody);

        return(pBuffer);
    }
Example #20
0
 public void Write(ByteBuffer buf)
 {
     buf.WriteByte(Id);
     buf.WriteByte(Flying);
     buf.WriteByte(NoClip);
     buf.WriteByte(Speeding);
     buf.WriteByte(SpawnControl);
     buf.WriteByte(ThirdPerson);
     buf.WriteShort(JumpHeight);
 }
Example #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="bcount"></param>
        /// <param name="totalcount"></param>
        /// <returns></returns>
        private ByteBuffer GetTagBuffer(IEnumerable <Tagbase> tags, short bcount, short totalcount)
        {
            ByteBuffer re = Parent.Allocate(APIConst.TagInfoRequestFun, tags.Count() * 302 + 9);

            re.Write(QueryAllTagNameAndIds);
            re.Write(totalcount);
            re.Write(bcount);
            re.Write(tags.Count());
            foreach (var vv in tags)
            {
                re.Write(vv.Id);
                re.Write(vv.FullName);
                re.WriteByte((byte)vv.Type);
            }
            return(re);
        }
Example #22
0
        public byte[] ToByteArray()
        {
            using (ByteBuffer writer = new ByteBuffer())
            {
                writer.WriteByte((byte)this.Count);

                foreach (Movement movement in this)
                {
                    writer.WriteBytes(movement.ToByteArray());
                }

                writer.Flip();

                return(writer.GetContent());
            }
        }
Example #23
0
        /// <summary>
        /// Generates a compatible block data array for network use
        /// </summary>
        public byte[] Serialize(bool customBlocks, bool blockDefinitions)
        {
            if (customBlocks && blockDefinitions)
            {
                return((byte[])Blocks.Clone());
            }

            ByteBuffer buffer = new ByteBuffer(4 + Blocks.Length);

            buffer.WriteInt(Blocks.Length);
            for (int i = 0; i < Blocks.Length; i++)
            {
                buffer.WriteByte(BlockDefinitions.GetFallback(Blocks[i], customBlocks, blockDefinitions));
            }

            return(buffer.Data);
        }
        /// <summary>
        /// Sends a CpeMessage to the client
        /// <para>NOTE: CpeMessages are single lined, therefore cannot be wrapped</para>
        /// </summary>
        public void SendCpeMessage(CpeMessageType type, string message)
        {
            if (type == CpeMessageType.Chat)
            {
                SendMessage(message); return;
            }
            if (message.Length > 64)
            {
                message = message.Substring(0, 64);
            }

            ByteBuffer buffer = new ByteBuffer(Opcodes.Message);

            buffer.WriteByte((byte)type);
            buffer.WriteString(message, UseCP437 ? Server.CP437 : Encoding.ASCII);
            SendRaw(buffer.Data);
        }
Example #25
0
        public static byte[] write()
        {
            buff = new ByteBuffer(45);
             buff.WriteD(45);
             buff.WriteD(0x7D2);
             buff.WriteD(1);
             buff.WriteD(4);
             buff.WriteD(3);
             buff.WriteD(559993);
             buff.WriteByte(0x05);
             buff.WriteDD(-313054979819954861);
             buff.WriteD(0);
             buff.WriteD(0);
             buff.WriteD(0);

             return buff.Get_ByteArray();
        }
Example #26
0
        public static ByteBuffer Write(VisualNode node)
        {
            ByteBuffer bfs = new ByteBuffer();

            bfs.WriteString(node.Title);
            bfs.WriteFloat(node.rect.x);
            bfs.WriteFloat(node.rect.y);
            bfs.WriteFloat(node.rect.width);
            bfs.WriteFloat(node.rect.height);
            bfs.WriteByte((byte)node.fields.Count);
            for (int i = 0; i < node.fields.Count; ++i)
            {
                bfs.WriteBytes(FieldNode.Write(node.fields[i]));
            }
            bfs.WriteBytes(FlowNode.Write(node.currentFlow));
            return(bfs);
        }
Example #27
0
    public static byte[] CreateInBinary(NodeGraph data)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteString(data.Name);
        buffer.WriteByte((byte)data.Type);
        buffer.WriteString(data.ScriptName);
        buffer.WriteInt32(data.Weight);
        buffer.WriteFloat(data.NodeRect.x);
        buffer.WriteFloat(data.NodeRect.y);
        buffer.WriteInt32(data.Nodes.Count);
        for (int i = 0; i < data.Nodes.Count; ++i)
        {
            buffer.WriteBytes(CreateInBinary(data.Nodes[i]));
        }
        return(buffer.Getbuffer());
    }
Example #28
0
        public void OnMessage(ClientSession session, ByteBuffer buffer)
        {
            string str = buffer.ReadString();
            int    uid = buffer.ReadInt();

            ushort     commandId = (ushort)Protocal.Login;
            ByteBuffer newBuffer = new ByteBuffer();

            newBuffer.WriteShort(commandId);
            newBuffer.WriteByte(1);
            newBuffer.WriteString(str);
            SocketUtil.SendMessage(session, newBuffer);

            session.uid = uid;
            UserUtil.Add(uid, session);
            Console.WriteLine("OnMessage--->>>" + str + uid);
        }
Example #29
0
        public ByteBuffer PatchRawMethodBody(MethodDefinition method, CodeWriter writer, out MethodSymbols symbols)
        {
            var buffer = new ByteBuffer();

            symbols = new MethodSymbols(method.Name);

            this.method    = method;
            reader.context = method;

            MoveTo(method.RVA);

            var flags = ReadByte();

            MetadataToken local_var_token;

            switch (flags & 0x3)
            {
            case 0x2:             // tiny
                buffer.WriteByte(flags);
                local_var_token   = MetadataToken.Zero;
                symbols.code_size = flags >> 2;
                PatchRawCode(buffer, symbols.code_size, writer);
                break;

            case 0x3:             // fat
                base.position--;

                PatchRawFatMethod(buffer, symbols, writer, out local_var_token);
                break;

            default:
                throw new NotSupportedException();
            }

            var symbol_reader = reader.module.symbol_reader;

            if (symbol_reader != null && writer.metadata.write_symbols)
            {
                symbols.method_token    = GetOriginalToken(writer.metadata, method);
                symbols.local_var_token = local_var_token;
                symbol_reader.Read(symbols);
            }

            return(buffer);
        }
Example #30
0
    private static int WriteByte(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 2);
            ByteBuffer byteBuffer = (ByteBuffer)ToLua.CheckObject(L, 1, typeof(ByteBuffer));
            byte       v          = (byte)LuaDLL.luaL_checknumber(L, 2);
            byteBuffer.WriteByte(v);
            result = 0;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
        public void ByteBuffer_AutoResize()
        {
            var buffer = new ByteBuffer();

            if (buffer.Bytes.Length != 0)
            {
                Assert.Fail();
            }

            buffer.WriteByte(200);
            buffer.WriteInt16(140);
            buffer.WriteInt32(7587383);
            buffer.WriteBytes(new byte[] { 73, 92, 6, 201, 88 });

            if (buffer.Bytes.Length != 1 + 2 + 4 + 5)
            {
                Assert.Fail();
            }
        }
Example #32
0
        /// <summary>
        /// pblua消息
        /// </summary>
        /// <param name="session"></param>
        /// <param name="buffer"></param>
        void OnPbLuaMessage(ClientSession session, ByteBuffer buffer)
        {
            LoginRequest request = ProtoUtil.GetMessage <LoginRequest>(buffer);

            Console.WriteLine("OnPbLuaMessage id=>>" + request.id + " name:>>>" + request.name + " email:>>" + request.email);
            buffer.Close(); buffer = null;

            LoginResponse response = new LoginResponse();

            response.id = 100; //排队人数
            byte[] data = ProtoUtil.SetMessage <LoginResponse>(response);

            ByteBuffer newBuffer = new ByteBuffer();

            newBuffer.WriteByte((byte)ProtocalType.PB_LUA);
            newBuffer.WriteBytes(data); //添加数据

            SocketUtil.SendMessage(session, Protocal.Login, newBuffer);
        }
Example #33
0
        private void HandlePrivateMessage(BinaryReader buffer)
        {
            var    message = (PrivateMessage)serializer.Deserialize(buffer.ReadBytes(BUFFERSIZE));
            Client client;

            if (MainForm.Clients.TryGetValue(message.To.Identity, out client))
            {
                ByteBuffer toMessage = new ByteBuffer();
                toMessage.WriteByte((byte)Protocol.PrivateMessage)
                .WriteByteArray(serializer.Serialize(new PrivateMessage()
                {
                    To = new User()
                    {
                        Identity = this.Identity, Name = this.Name
                    }, Message = message.Message
                }));
                client.Socket.Send(toMessage.ToArray());
            }
        }
Example #34
0
        static void Main(string[] args)
        {
            Console.Title = "Nexus Shard Server";

            Console.WriteLine("Nexus Shard Server\n");
            Utility.WriteLegal();
            Console.WriteLine("");

            AsyncServer server = new AsyncServer(IPAddress.Parse("0.0.0.0"), 20063);
            server.Start();

            server.ConnectionAccepted += new AsyncServer.ConnectionAcceptedHandler(connection =>
            {
                TORLog.Network("CnxAccept => " + connection.GetHashCode());
                connection.DataReceived += new AsyncConnection.ConnectionDataReceivedHandler(data =>
                {
                    if (connection.State == 1)
                    {
                        // rsa packet
                        connection.SetState(2);
                        connection.SendPacket(new SMsg_ClientSignatureRequest("OmegaServerProxyObjectName", 0x0174F5));
                        return;
                    }

                    ByteBuffer buffer = new ByteBuffer(ByteOrder.LittleEndian, data);
                    byte opcode = (byte)buffer.ReadByte();

                    byte[] len_data = buffer.ReadBytes(4);
                    byte chk = (byte)buffer.ReadByte();
                    uint packetid = buffer.ReadUInt();

                    if (chk != (byte)(opcode ^ len_data[0] ^ len_data[1] ^ len_data[2] ^ len_data[3]))
                    {
                        TORLog.Warn("Received packet with invalid checksum!");
                    }

                    if (opcode == 1) // Client Ping Packet
                    {
                        TORLog.Network("Ping from " + connection.GetHashCode() + " Seq = " + packetid);
                        ByteBuffer response = new ByteBuffer(ByteOrder.LittleEndian);
                        response.WriteByte(2); // Pong OPC = 2
                        response.WriteInt(0); // Pong Len
                        response.WriteByte(0); // Pong Chk
                        response.WriteUInt(packetid); // Pong
                        response.WriteInt(0);
                        response.WriteInt(1);
                        response.WriteByte(0);
                        connection.SendTORPacket(response);
                        return;
                    }

                    string packetname = OpcodeManager.Instance.GetPacketName(opcode, packetid);

                    if (packetname == "")
                    {
                        TORLog.Warn("Received unknown packet from SWTOR client\nOpcode = 0x" + opcode.ToString("X2") + " -- PacketID = 0x" + packetid.ToString("X8"));
                        TORLog.Warn("--- dump ---");
                        TORLog.Warn(Utility.HexDump(data));
                    }
                    else
                    {
                        try
                        {
                            IClientPacket pkt = Activator.CreateInstance(Type.GetType("ShardServer.Packets.Client." + packetname)) as IClientPacket;
                            TORLog.Network("PktRecv @ " + connection.GetHashCode() + " << " + packetname);
                            pkt.ExecutePacket(connection, buffer);
                        }
                        catch (Exception ex)
                        {
                            TORLog.Error("Exception occured while processing " + packetname, ex);
                        }
                    }
                });
                // Send HELLO packet
                connection.SendClear(new byte[] { 0x03, 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
                // State is 1
                connection.SetState(1);
                connection.EngageReading();
            });

            TORLog.Info("SHARD Server running, press Enter to exit ...");
            Console.ReadLine();
        }
Example #35
0
        void WriteCharacterInfo(ByteBuffer packet, Character cha, byte add)
        {
            packet.WriteBytes(new byte[] { (byte)(0x86 + add), 0x00, 0x00, 0x40 }); // Dynamic
            packet.WriteUInt(0x4e7511aa); // Static
            packet.WriteUInt(0x899);
            packet.WriteByte(0x80);

            packet.WriteBytes(new byte[] {
                0xe8, 0x7e, 0x20, 0x9b, // E8 7E 20 9B
                (byte)(0x86 + add), 0x00, 0x00, 0x40, // 4F 00 00 40
                0xe8, 0x7e, 0x20, 0x9b, // E8 7E 20 9B
                (byte)(0x86 + add), 0x00, 0x00, 0x40, // 4F 00 00 40
            });

            packet.WriteBytes(new byte[] { 0x05, 0x00, 0x02 });

            long detailsLengthPlaceholder = packet.Position;
            packet.WriteInt(0); // placeholder for details length

            packet.WriteBytes(new byte[] {
                0x14, 0x14, 0xCF, 0x40,
                0x00, 0x00, 0x04, 0xE0,
                0xD7, 0x68, 0xB5, 0x03,
                0x01, 0xCC, 0x07, 0xD8,
                0x87, 0xD6, 0x02, 0x03,
                0x00, 0xCC, 0x29, 0x40,
                0x56, 0x77, 0x5B, 0x03,
                0x01, 0xC4, 0x30, 0x1A,
                0x0D, 0x75, 0xB9, 0x15,
                0xCD, 0x0B,
            }); // static

            packet.WriteBytes(new byte[] { 0xcc, 0xbd, 0x33, 0x9c, 0xdd }); // unk dynamic (CC BD 33 9C DD)

            packet.WriteBytes(new byte[] {
                0xCC, 0x07, 0x18, 0xC2,
                0x55, 0x7C, 0x09, 0x04,
                0x04, 0xCF, 0x40, 0x00,
                0x00, 0x30, 0x5C, 0x21,
                0xB1, 0x10, 0x02 }); // static

            packet.WriteBytes(new byte[] {
            //0x95, 0x01, 0x02,
            //0xC9, 0x02, 0x8A, 0x01, 0x02,
            //0xC9, 0x02, 0x8C, 0x01, 0x02, 0x9C, // C9 02 FC 01 02 8A 01 02 C9 02 F5 01 02 C9 03 08
            0xC9, 0x02, 0xFC, 0x01, 0x02, 0x8A, 0x01, 0x02,
            0xC9, 0x02, 0xF5, 0x01, 0x02, 0xC9, 0x03, 0x08,

            0xCB, 0x91, 0xFC, 0x05,
            0xB8, 0x02,
            0x06, 0xCC, 0x27, 0x32, 0x2B, // static
            0x0D, 0xFD, 0x02, 0xCA, // static
            0x76, // static

            0xc4, 0x7f, // dynamic

            0xCB, 0x50, 0x5D, 0x6C, 0xC6, // static

            0x04, 0x33, 0x83, 0xc5, // static
            0x44, // static
            0x01, // static
            0x04, 0x9a, 0xdd, 0xdc, // static
            0x45,
            0xC4, 0x25, 0x42, 0x9A, // Static
            0x25, 0xBA, 0x02, 0xCF }); // Static

            packet.WriteUInt(cha.APP1);
            packet.WriteUInt(cha.APP2);
            packet.WriteUInt(cha.APP3);
            packet.WriteUShort(cha.APP4);
            packet.WriteByte(0xCF);

            /*packet.WriteBytes(new byte[] {
                0x56, 0xF6, 0x33, 0xF2, //0E B2 4F F8
                0xDD, 0xDE, 0x74, 0x77, //51 1E 46 3C
                0xCB, 0x6C, 0x9C, 0xB1, //CB 6C 9C B1
                0xA7, 0x01, 0xCF,
                //0xE0, 0x00, 0xFD, 0x35, 0xB1, 0x0B, 0x17, 0x60 //9B E1 60
            });*/ // appearance ? from char creation

            //packet.WriteBytes(BitConverter.GetBytes((ulong)CharacterClass.JediConsular));
            packet.WriteULongRev((ulong)cha.Class);

            packet.WriteBytes(new byte[] { 0xCC, 0x25, 0xEB, 0x85,
            0x46, 0x42, 0x03, 0x01, // 0 = 1
            0xC4, 0x25, 0xD0, 0x6C, 0xA1,
                0x13, 0x07,
            });

            // Inventory
            ulong[] ids = new ulong[] { 0xe000e32eacf6fe1c, 0xe00096830962E510, 0xE0002D97FFB1222D };
            packet.WriteByte(1);
            packet.WriteByte((byte)ids.Count());
            packet.WriteByte((byte)ids.Count());
            packet.WriteByte(1);
            packet.WriteByte(0xcf);

            int ctr = 0;
            foreach (ulong id in ids)
            {
                packet.WriteULongRev(id);
                if (ctr == 0) packet.WriteByte(0x02);
                else if (ctr == 1) packet.WriteByte(0x03);
                else packet.WriteShort(0x211);
                packet.WriteByte(0xcf);
                ctr++;
            }
            // End Inventory

            packet.WriteBytes(new byte[] {
                0x15, 0xE2,
                0x38, // 2D
                0x19, 0xB0, 0x9F,
                0xDB, 0x62, // C8 B1
                0xCC, 0x02, 0xEE, 0xCD, 0xCF, 0x87, 0x08, 0x00, }); // Static

            // Appearance
            packet.WriteByte(2);
            packet.WriteByte((byte)cha.Appearance.Length);
            packet.WriteByte((byte)cha.Appearance.Length);

            //cha.Appearance.OrderBy(tuple => tuple.Item1);

            // 01 05 07 0A 0B 0C 0E 10
            byte counter = 0;
            for (byte b = 0; b < cha.Appearance.Length; b++)
            {
                Tuple<byte, byte> tuple = cha.Appearance[b];
                packet.WriteByte(0xD2);
                if (tuple.Item1 < 0x0A)
                {
                    packet.WriteByte(0x01);
                    packet.WriteByte((byte)(0x30 + tuple.Item1));
                }
                else
                {
                    packet.WriteByte(0x02);
                    packet.WriteByte(0x31);
                    packet.WriteByte((byte)(0x30 + (tuple.Item1 - 0x0A)));
                }
                packet.WriteByte(0xc9);
                packet.WriteByte(0x04);
                packet.WriteByte(tuple.Item2);
                counter++;
            }
            packet.WriteByte(0xcf);

            // End Appearance

            /*packet.WriteBytes(new byte[] {
                0x02, 0x08, 0x08,
                0xD2, 0x01, 0x31, 0xC9, 0x04, 0x5D,
                0xD2, 0x01, 0x35, 0xC9, 0x04, 0x8B,
                0xD2, 0x01, 0x37, 0xC9, 0x04, 0x3D,
                0xD2, 0x02, 0x31, 0x30, 0xC9, 0x04, 0x51,
                0xD2, 0x02, 0x31, 0x31, 0xC9, 0x04, 0x46,
                0xD2, 0x02, 0x31, 0x32, 0xC9, 0x04, 0x83,
                0xD2, 0x02, 0x31, 0x34, 0xC9, 0x04, 0x20,
                0xD2, 0x02, 0x31, 0x36, 0xC9, 0x04, 0xA8,
                0xCF
            });*/ // list of something

            packet.WriteBytes(new byte[] {
                0x3F, 0xFF, 0xFF, 0xF5,
                0x58, 0x76, 0x5E, 0x0F, 0x01, 0xCF,
                0x40, 0x00, 0x00, (byte)(0x86 + add),
                0x9b, 0x20, 0x7f, 0xa5, // 9B 20 7F A5
                0x01, 0x06
            });

            // Character Name
            packet.WriteByte((byte)cha.Name.Length);
            packet.WriteBytes(Encoding.UTF8.GetBytes(cha.Name));

            packet.WriteShort(0x202); // Static

            packet.WriteByte(cha.Level); // Character Level

            packet.WriteShort(0x103);

            packet.WriteByte(0xcf); // Separator

            packet.WriteBytes(Utility.Reverse(BitConverter.GetBytes((ulong)cha.AreaSpec))); // Current Map ID

            packet.WriteBytes(new byte[] {
                0xC7, 0x3F, 0xFF, 0xFF, // This is static - probably a separator
                0xD2, 0xA9, 0x55, 0x93, // static
                0x1A, 0x02, 0x01, 0xc7, // static ? or some len/offset data for next char
                0xaf, 0xff, 0xc0, // dynamic unk
            });

            long curPos = packet.Position;
            packet.Position = detailsLengthPlaceholder;

            int value = (int)(curPos - detailsLengthPlaceholder - 8);
            Console.WriteLine("Len = " + value);

            packet.WriteInt((int)(curPos - detailsLengthPlaceholder - 8));
            packet.Position = curPos;
        }
Example #36
0
        public void SendTORPacket(ByteBuffer buffer)
        {
            // here we receive a buffer prepared for length insertion
            int length = (int)buffer.Position;
            buffer.Position = 1;
            buffer.WriteInt(length);

            byte[] data = buffer.ToArray();
            byte chk = (byte)(data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4]);

            buffer.WriteByte(chk);

            SendRegularPacket(buffer.ToArray());
        }