Example #1
0
        public static void QueryCashItem(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            builder.New(0x1A2);
            {
                Character character  = client.Metadata["fullchar"] as Character;
                var       cid        = character.id;
                var       server     = (int)client.Metadata["server"];
                var       syncServer = client.Metadata["syncServer"] as SyncReceiver;

                var CashItens = CharacterManagement.GetCashItem(syncServer, server, cid / 8);


                /*
                 * builder += (int)2;          //item qnt
                 *
                 * builder += (int)1;          //item cashid
                 * builder += (int)163865;         //item idx
                 * builder += (byte)0xF4;
                 * builder += (byte)0x00;
                 * builder += (byte)0x00;
                 * builder += (byte)0x00;
                 * //builder += (int)0x000000E4;          //item opt extreme
                 * builder += (int)536871167;  //item opt old
                 * builder += (int)0;
                 * builder += (byte)31;         //duration
                 *
                 * builder += (int)2;          //item cashid
                 * builder += (int)24;         //item idx
                 * builder += (int)4;          //item opt extreme
                 * builder += (int)536871167;  //item opt old
                 * builder += (int)0;
                 * builder += (byte)17;        //duration
                 */



                builder += CashItens.Length;

                foreach (var i in CashItens)
                {
                    builder += (int)i.ID;
                    builder += (int)i.itemid;
                    builder += i.itemopt;
                    builder += (int)i.itemopt2;
                    builder += (byte)i.duration;
                }

                /*
                 * builder += (int)2; //item qnt
                 *
                 * builder += (int)1; //item cashid
                 * builder += (int)25; //item idx
                 * builder += (int)536880405; //item opt
                 * builder += (byte)0; //duration
                 *
                 * builder += (int)2; //item cashid
                 * builder += (int)25; //item idx
                 * builder += (int)0; //item opt
                 * builder += (byte)0; //duration*/
            }

            client.Send(builder, "QueryCashItem");
        }
Example #2
0
        public static void MessageEvent(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            //byte[] b;

            var name = client.Metadata["name"] as string;
            var x    = (ushort)client.Metadata["x"];
            var y    = (ushort)client.Metadata["y"];
            var id   = (uint)client.Metadata["id"];
            var cid  = (uint)client.Metadata["cid"];
            var map  = client.Metadata["map"] as IMap;

            int size = packet.ReadByte() - 3;

            packet.Skip(2);
            var type = packet.ReadByte();
            var msg  = packet.ReadString(size);
            var smsg = msg.Split(' ');

            if (msg == "/quit")
            {
                client.Disconnect();
                return;
            }

            if (smsg.Length > 1 && smsg[0] == "/drop")
            {
                int itemid = 0;

                if (int.TryParse(smsg[1], out itemid))
                {
                    map.DropItem(x, y, itemid, cid, id);
                }

                return;
            }

            var clients = map.GetSurroundingClients(client, 1);

            if (smsg.Length > 1 && smsg[0] == "/spawn")
            {
                ushort mobid = 0;

                if (!ushort.TryParse(smsg[1], out mobid))
                {
                    return;
                }

                var p = client.CreatePacket("MobSpawned", mobid);

                client.Send(p, "MobSpawned");

                return;
            }

            if (msg == "/partytime")
            {
                uint pid = 1337;

                foreach (var c in clients)
                {
                    builder.New(0xC9);
                    {
                        builder += (int)pid;
                        builder += (byte)12;

                        //b = builder.Data;
                    }

                    var timestamp = (uint)c.Metadata["timestamp"];
                    var style     = (uint)c.Metadata["style"];

                    c.Send(builder, "UnknownPacket_0xC9");

                    builder.New(0xC8);
                    {
                        builder += (short)0x3101;
                        builder += (int)pid++;
                        builder += (short)0x000D;
                        builder += (short)0x0100;
                        builder += 1;
                        builder += Environment.TickCount - (int)timestamp;
                        builder += (short)(x + 1);
                        builder += (short)y;
                        builder += (short)(x + 1);
                        builder += (short)y;
                        builder += (byte)0;
                        builder += 0;
                        builder += (short)0;
                        builder += (int)style;
                        builder += (byte)1;
                        builder += (byte)0;
                        builder += 0;
                        builder += 0;
                        builder += (byte)0;

                        var equipment = (List <CItem>)c.Metadata["equipment"];

                        builder += (byte)(equipment.Count);
                        builder += (short)0;
                        builder += (byte)0;
                        builder += 0;

                        name = "PARTY TIME!!";

                        builder += (byte)(name.Length + 1);
                        builder += name;
                        builder += (byte)0;

                        foreach (var e in equipment)
                        {
                            builder += (short)e.ID;
                            builder += (byte)e.Slot;
                        }

                        //b = builder.Data;
                    }

                    c.Send(builder, "UnknownPacket_0xC8");
                }

                return;
            }

            foreach (var c in clients)
            {
                builder.New(0xD9);
                {
                    builder += (int)cid;
                    builder += (byte)(msg.Length + 3);
                    builder += (byte)0xFE;
                    builder += (byte)0xFE;
                    builder += type;
                    builder += msg;

                    //b = builder.Data;
                }

                c.Send(builder, "MessageEvnt");
            }

            events.SaidLocal("world.700.MessageEvnt", (int)cid, name, msg);
        }
Example #3
0
        public static void Unknown191(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            builder.New(0x0191);

            client.Send(builder, "Unknown191");
        }
Example #4
0
        /*
         * CSC_ATTCKTOMOBS Packet
         * -------------------------
         * Client2Server Structure:
         *
         * ushort  : magic code
         * ushort  : size
         * int     : padding
         * ushort  : opcode
         *
         * ushort  : MobID
         * byte    : MapID
         * byte    : Unkn1             #so far its value as been 2
         * byte    : Unkn2             #so far its value as been 2 as well, so it could be just a short (512)
         * byte    : Unkn3             #so far its value as been 0
         * -------------------------
         * Server2Client Structure:
         *
         * ushort  : magic code
         * ushort  : size
         * ushort  : opcode
         *
         * ushort  : MobID
         * byte    : Unkn1
         * byte    : MapID
         * byte    : Unkn2
         * uint    : CurHp             #Current HP/Life character has.
         * uint    : CurMp             #Current MP/Mana character has.
         * byte[2] : Unkn4             #so far its value as been 00 00
         * byte    : AtkResult         #Enum AttackResult -> Critical = 1; Normal = 2; Block = 1B; Miss = 15;
         * byte    : HitCounter        #Counts number of attacks made to mob
         * byte    : Unkn5             #Usually value between 1 and 3
         * byte[6] : Unkn6             #00
         * uint    : Dmg               #Damage inflicted on mob, Miss = 0; Dmg = Attack - Mob Defense; if(dmg<=0 && !Miss) dmg = 1;
         * uint    : MobHp             #MobHp -= Dmg
         * ushort  : AP
         * uint    : AXP
         * byte    : TakeDmg           #Hp Cost/Hp Sacrifice; Boolean;
         * uint    : HpHover           #Hp where 0/20 sp is displayed if TakeDmg = 1.
         * uint    : DmgTaken          #Amount of dmg recieved/hp sacrificed if TakeDmg = 1.
         * -------------------------
         * Server sends Notify packet OpCode 0x00E1;
         */

        public static void NormalAttack(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            var map     = client.Metadata["map"] as IMap;
            var mapmobs = (client.Metadata["map"] as IMap).GetSurroundingMobs(client, 3);
            var mobdata = map.GetMobsData;

            var MobID = packet.ReadUShort();
            var unk1  = packet.ReadByte();
            var MapID = packet.ReadByte();
            var unk2  = packet.ReadUShort();

            Character character  = client.Metadata["fullchar"] as Character;
            var       cid        = character.id;
            var       server     = (int)client.Metadata["server"];
            var       syncServer = client.Metadata["syncServer"] as SyncReceiver;
            var       slot       = character.slot;

#if DEBUG
            Log.Message(string.Format("'{0}' '{1}' '{2}' '{3}'", MobID, unk1, MapID, unk2), ConsoleColor.Red, "PACKET RECV");
#endif

            var mi = mapmobs.Find(x => x.Id == MobID);

            var md = mobdata[mi.SId];


            //uint defense = Convert.ToUInt32(new Random().Next(1, 10));
            uint attack_rate = Convert.ToUInt32(new Random().Next(1, 10));
            //uint atk = character.stats.str_stat*2;   //Attempt dmg formula
            var atk = (int)client.Metadata["patk"];
            //uint dmg = atk - defense;

            var mobdef        = new Random().Next(md.Defense, md.DefRate);
            var normal_damage = atk - mobdef;
            var crit_damage   = normal_damage + (normal_damage * 20 / 100);
            var dmg           = 0;

            var atack_result = 0;

            if (attack_rate > 0)
            {
                if (attack_rate < 7)
                {
                    if (attack_rate <= 5)
                    {
                        atack_result        = 2;
                        dmg                 = normal_damage;
                        character.stats.exp = character.stats.exp + (ulong)dmg * 2;
                    }
                    if (attack_rate == 6)
                    {
                        atack_result        = 1;
                        dmg                 = crit_damage;
                        character.stats.exp = character.stats.exp + (ulong)dmg * 2;
                    }
                }
                if (attack_rate == 7)
                {
                    atack_result = 27;
                    dmg          = 0;
                }
                if (attack_rate >= 8)
                {
                    atack_result = 21;
                    dmg          = 0;
                }
            }

            if (dmg < md.Defense && dmg < 0)
            {
                dmg = new Random().Next(1, atk);
                character.stats.exp = character.stats.exp + 1;
            }
            if (dmg >= mi.CurrentHP)
            {
                dmg          = mi.CurrentHP;
                mi.CurrentHP = 0;
                //map.DropItem(mi.CurrentPosX, mi.CurrentPosX, 13, 1,1);
            }
            else
            {
                mi.CurrentHP = mi.CurrentHP - dmg;
            }

            ushort maxhp = character.stats.maxhp;
            ushort maxmp = character.stats.maxhp;

            ushort curhp = character.stats.curhp;
            ushort curmp = character.stats.curmp;

            builder.New(0x00B0);
            {
                builder += (short)MobID;
                builder += (byte)unk1;
                builder += (byte)MapID;
                builder += (byte)unk2;
                builder += (uint)curhp;
                builder += (uint)curmp;
                builder += new byte[2];               // Unknown4 ( so far always 00 00 )
                builder += (byte)atack_result;        // AttackResult;
                builder += (byte)0x1B;                // HitCounter
                builder += (byte)0x3;                 // Unknown5
                builder += new byte[6];               // Unknown6


                builder += (ulong)0;                    // OXP
                //builder += (uint)0;               // EXP
                builder += (uint)dmg;                   // DMG take on mob
                builder += (ushort)mi.CurrentHP;        // MobHp
                builder += (byte)0;                     // TakeDmg
                builder += (uint)0;                     // HpHover
                builder += (uint)0;                     // DmgTaken
                builder += (uint)curhp;
                builder += (uint)0;
            }



            if (curhp > 0)
            {
                character.stats.curhp = curhp;
                character.stats.curmp = curmp;
            }

            else
            {
                #region Death PacketInfo

                /*
                 * Death PacketInfo
                 * Server sends ErrorCode Msg (15 = Dead Menu where player can ressurect)
                 * Server sends Packet 0x042B
                 */
                #endregion

                character.stats.curhp = maxhp;
                character.stats.curmp = maxmp;

                var p = client.CreatePacket("ErrorCode", packet.Opcode, (ushort)0, (ushort)15, (ushort)map.ID);
                client.Send(p, "ErrorCode");

                builder.New(0x042B);
                {
                    builder += 0;
                    builder += 0;
                    builder += 0;
                }

                client.Send(builder, "unk2");
            }


#if DEBUG
            string notice = "";
            for (int i = 0; i < builder.Size; i++)
            {
                notice += builder.Data[i].ToString("X2") + " ";
            }

            Log.Notice(notice);
#endif

            client.Send(builder, "NormalAttack");

            if (mi.CurrentHP == 0)
            {
                mi.Spawn = Environment.TickCount + md.Respawn * 10;
            }
        }
Example #5
0
        public static void ChangeMapCell(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            //byte[] b;

            packet.Skip(4);
            var x = packet.ReadShort();
            var y = packet.ReadShort();

            var map = client.Metadata["map"] as IMap;

            map.MoveClient(client, x / 16, y / 16);

            var clients = (client.Metadata["map"] as IMap).GetSurroundingClients(client, 2);

            if (clients.Count > 1)
            {
                builder.New(0xC8);
                {
                    builder += (short)(clients.Count - 1);

                    foreach (var c in clients)
                    {
                        if (c == client)
                        {
                            continue;
                        }
                        //if (!c.Metadata.ContainsKey("id") || (uint)c.Metadata["cid"] == 0) continue;

                        var id        = (uint)c.Metadata["cid"];
                        var level     = (uint)c.Metadata["level"];
                        var timestamp = (uint)c.Metadata["timestamp"];
                        var px        = (ushort)c.Metadata["x"];
                        var py        = (ushort)c.Metadata["y"];
                        var dx        = (ushort)c.Metadata["dest_x"];
                        var dy        = (ushort)c.Metadata["dest_y"];
                        var style     = (uint)c.Metadata["style"];

                        builder += (int)id;
                        builder += (short)0x000D;
                        builder += (short)0x0100;
                        builder += (int)level;
                        builder += Environment.TickCount - (int)timestamp;
                        builder += (short)px;
                        builder += (short)py;
                        builder += (short)dx;
                        builder += (short)dy;
                        builder += (byte)0;                             // PK penalty
                        builder += 0;
                        builder += (short)0;
                        builder += (int)style;
                        builder += (byte)0;                             // Animation ID
                        builder += 0;
                        builder += 0;
                        builder += (byte)0;
                        builder += (byte)0;                             // 1 = dead

                        var equipment = (List <CItem>)c.Metadata["equipment"];

                        builder += (byte)equipment.Count;
                        builder += (short)0;
                        builder += (byte)0;                             // 1 = has private shop open
                        builder += 0;

                        var name = c.Metadata["name"] as string;

                        builder += (byte)(name.Length + 1);
                        builder += name;
                        builder += (byte)0;

                        foreach (var e in equipment)
                        {
                            builder += (short)e.ID;
                            builder += (byte)e.Slot;
                        }
                    }

                    //b = builder.Data;
                }

                client.Send(builder, "UnknownPacket_0xC8");

                // nested wooooooo!
                {
                    var id        = (uint)client.Metadata["cid"];
                    var level     = (uint)client.Metadata["level"];
                    var timestamp = (uint)client.Metadata["timestamp"];
                    var px        = (ushort)client.Metadata["x"];
                    var py        = (ushort)client.Metadata["y"];
                    var dx        = (ushort)client.Metadata["dest_x"];
                    var dy        = (ushort)client.Metadata["dest_y"];
                    var style     = (uint)client.Metadata["style"];

                    builder.New(0xC8);
                    {
                        builder += (ushort)0x3101;
                        builder += (int)id;
                        builder += (short)0x000D;
                        builder += (short)0x0100;
                        builder += (int)level;
                        builder += Environment.TickCount - (int)timestamp;
                        builder += (short)px;
                        builder += (short)py;
                        builder += (short)dx;
                        builder += (short)dy;
                        builder += (byte)0;                             // PK penalty
                        builder += 0;
                        builder += (short)0;
                        builder += (int)style;
                        builder += (byte)0;                             // Animation ID
                        builder += 0;
                        builder += 0;
                        builder += (byte)0;
                        builder += (byte)0;                             // 1 = dead

                        var equipment = (List <CItem>)client.Metadata["equipment"];

                        builder += (byte)equipment.Count;
                        builder += (short)0;
                        builder += (byte)0;
                        builder += 0;

                        var name = client.Metadata["name"] as string;

                        builder += (byte)(name.Length + 1);
                        builder += name;
                        builder += (byte)0;

                        foreach (var e in equipment)
                        {
                            builder += e.ID;
                            builder += (byte)e.Slot;
                        }

                        //b = builder.Data;
                    }

                    foreach (var c in clients)
                    {
                        if (c == client)
                        {
                            continue;
                        }

                        //var b2 = b;

                        c.Send(builder, "UnknownPacket_0xC8");
                    }
                }
            }
        }