ModifyIndex() public method

public ModifyIndex ( int i ) : void
i int
return void
Example #1
0
        public static unsafe void MoveItem(byte* ptr, int Index_)
        {
            Silkroad.C_S.MOVE_ITEM* tmpPtr = (Silkroad.C_S.MOVE_ITEM*)ptr;

            PacketWriter writer = new PacketWriter();
            switch (tmpPtr->Type)
            {
                case 0:

                    int[] CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);
                    Silkroad.Item_ SourceItem_ = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                    Silkroad.Item_ DestinationItem_ = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Destination]]);

                    if (SourceItem_.ITEM_TYPE_NAME.Contains("FRPVP_VOUCHER"))
                    {
                        if (Player.Stats[Index_].Level >= 10 && CheckItemGender(SourceItem_, Index_))
                        {
                            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ANIMATION_CAPE);
                            writer.AppendDword(Player.General[Index_].UniqueID);
                            writer.AppendWord(0x102);
                            writer.AppendByte(0xA);

                            ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);
                            Timers.UsingItemTimer[Index_].Interval = 10000;
                            Player.Objects[Index_].SourceItemIndex = CharacterItemIndex[tmpPtr->Source];
                            Player.Objects[Index_].DestinationItemIndex = CharacterItemIndex[tmpPtr->Destination];
                            Timers.UsingItemTimer[Index_].Start();
                        }
                        else
                        {
                            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                            writer.AppendWord(0x1002);
                            ServerSocket.Send(writer.getWorkspace(), Index_);
                        }
                    }
                    else
                    {
                        if (tmpPtr->Destination < 13)
                        {
                            if (!SourceItem_.ITEM_TYPE_NAME.Contains("ETC"))
                            {
                                if (!CheckItemGender(SourceItem_, Index_))
                                {
                                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                                    writer.AppendWord(0x1602);
                                    ServerSocket.Send(writer.getWorkspace(), Index_);
                                    return;
                                }
                                else if (!CheckItemLevel(SourceItem_, Index_))
                                {
                                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                                    writer.AppendWord(0x1002);
                                    ServerSocket.Send(writer.getWorkspace(), Index_);
                                    return;
                                }

                                if (tmpPtr->Destination == 6)
                                    Player.General[Index_].WeaponType = SourceItem_.CLASS_C;

                                Silkroad.Item_ WeaponItem = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[6]]);

                                Console.WriteLine(WeaponItem.CLASS_C);
                                if (tmpPtr->Destination == 6 && DatabaseCore.Item.ItemId[CharacterItemIndex[7]] != 0 && (Player.General[Index_].WeaponType != 2 && Player.General[Index_].WeaponType != 3 && Player.General[Index_].WeaponType != 7 && Player.General[Index_].WeaponType != 10 && Player.General[Index_].WeaponType != 15))
                                {
                                    byte unequipped = UnEnquipShield(Index_, CharacterItemIndex, CharacterItemIndex[7]);
                                    if (unequipped != 255)
                                        MoveItemToDatabase(CharacterItemIndex[7], unequipped, Player.General[Index_].CharacterName);
                                }

                                if (tmpPtr->Destination == 7 && DatabaseCore.Item.ItemId[CharacterItemIndex[6]] != 0 && (WeaponItem.CLASS_C != 2 && WeaponItem.CLASS_C != 3 && WeaponItem.CLASS_C != 7 && WeaponItem.CLASS_C != 10 && WeaponItem.CLASS_C != 15))
                                {
                                    byte unequipped = UnEnquipWeapon(Index_, CharacterItemIndex, CharacterItemIndex[6]);
                                    if (unequipped != 255)
                                        MoveItemToDatabase(CharacterItemIndex[6], unequipped, Player.General[Index_].CharacterName);
                                }

                                EquipItem(Index_, CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination]);
                            }
                            else
                            {
                                if (!(tmpPtr->Destination == 7 && (Player.General[Index_].WeaponType == 6 || Player.General[Index_].WeaponType == 12) && DatabaseCore.Item.ItemId[CharacterItemIndex[7]] != 0))
                                    return;
                            }
                        }
                        if (tmpPtr->Source < 13)
                            UnEquipItem(Index_, CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination]);

                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                        writer.AppendByte(1);
                        writer.AppendByte(tmpPtr->Type);
                        writer.AppendByte(tmpPtr->Source);
                        writer.AppendByte(tmpPtr->Destination);
                        writer.AppendWord(tmpPtr->Amount);
                        writer.AppendByte(0);
                        ServerSocket.Send(writer.getWorkspace(), Index_);

                        MoveItemToDatabase(CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination], Player.General[Index_].CharacterName);
                    }
                    Stats.OnStatPacket(Index_);
                    break;
                case 7:
                    CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);

                    int ItemIndex = Item.ItemAmount;
                    Item.General[ItemIndex].Pk2ID = DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]];
                    Item.General[ItemIndex].UniqueID = (uint)random.Next(76000000, 79999999);
                    Item.General[ItemIndex].Plus = DatabaseCore.Item.PlusValue[CharacterItemIndex[tmpPtr->Source]];
                    Item.General[ItemIndex].Durability = DatabaseCore.Item.Durability[CharacterItemIndex[tmpPtr->Source]];
                    Item.General[ItemIndex].Pickable = true;
                    Item.General[ItemIndex].Quantity = DatabaseCore.Item.Quantity[CharacterItemIndex[tmpPtr->Source]];
                    Item.Position[ItemIndex].XSector = Player.Position[Index_].XSector;
                    Item.Position[ItemIndex].YSector = Player.Position[Index_].YSector;
                    byte randomplace = (byte)random.Next(1, 7);
                    Item.Position[ItemIndex].X = Player.Position[Index_].X + randomplace;
                    Item.Position[ItemIndex].Z = Player.Position[Index_].Z;
                    Item.Position[ItemIndex].Y = Player.Position[Index_].Y + randomplace;
                    Item.General[ItemIndex].DroppedByUniqueId = Player.General[Index_].UniqueID;
                    Item.ItemAmount++;

                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                    writer.AppendByte(1);
                    writer.AppendByte(tmpPtr->Type);
                    writer.AppendByte(tmpPtr->Source);
                    ServerSocket.Send(writer.getWorkspace(), Index_);

                    Silkroad.Item_ tmpItem = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);

                    byte[] tmpBuffer = new byte[0];
                    if (tmpItem.ITEM_TYPE_NAME.Contains("CH") || tmpItem.ITEM_TYPE_NAME.Contains("EU"))
                    {
                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                        writer.AppendDword(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                        writer.AppendByte(DatabaseCore.Item.PlusValue[CharacterItemIndex[tmpPtr->Source]]);
                        writer.AppendDword(Item.General[ItemIndex].UniqueID);
                        writer.AppendByte(Item.Position[ItemIndex].XSector);
                        writer.AppendByte(Item.Position[ItemIndex].YSector);
                        writer.AppendFloat(Item.Position[ItemIndex].X);
                        writer.AppendFloat(Item.Position[ItemIndex].X);
                        writer.AppendFloat(Item.Position[ItemIndex].Y);
                        writer.AppendWord(0xAAA6);
                        writer.AppendByte(0);
                        writer.AppendByte(0);
                        writer.AppendByte(6);
                        writer.AppendDword(Item.General[ItemIndex].DroppedByUniqueId);
                        tmpBuffer = writer.getWorkspace();
                    }
                    else if (tmpItem.ITEM_TYPE_NAME.Contains("ETC"))
                    {
                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                        writer.AppendDword(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                        writer.AppendDword(Item.General[ItemIndex].UniqueID);
                        writer.AppendByte(Item.Position[ItemIndex].XSector);
                        writer.AppendByte(Item.Position[ItemIndex].YSector);
                        writer.AppendFloat(Item.Position[ItemIndex].X);
                        writer.AppendFloat(Item.Position[ItemIndex].X);
                        writer.AppendFloat(Item.Position[ItemIndex].Y);
                        writer.AppendWord(0xAAA6);
                        writer.AppendByte(0);
                        writer.AppendByte(0);
                        writer.AppendByte(6);
                        writer.AppendDword(Item.General[ItemIndex].DroppedByUniqueId);
                        tmpBuffer = writer.getWorkspace();
                    }

                    for (int i = 0; i < Player.PlayersOnline; i++)
                    {
                        if (Player.General[i].CharacterID != 0)
                        {
                            if (Formula.CalculateDistance(Item.Position[ItemIndex], Player.Position[i]) <= 800)
                            {
                                ServerSocket.Send(tmpBuffer, i);
                                Player.Objects[i].SpawnedItemsIndex.Add(ItemIndex);
                            }
                        }
                    }

                    DatabaseCore.WriteQuery("UPDATE items SET itemid='0',plusvalue='0' ,durability='30' WHERE itemnumber='item{0}' AND owner='{1}'", tmpPtr->Source, Player.General[Index_].CharacterName);
                    Stats.OnStatPacket(Index_);

                    DeleteFromDatabase(CharacterItemIndex[tmpPtr->Source]);

                    break;
                case 10:
                    if (Player.Stats[Index_].Gold != 0)
                    {
                        PacketReader reader = new PacketReader(ptr, 5);
                        reader.ModifyIndex(1);
                        uint goldamount = reader.ReadDword();

                        ItemIndex = Item.ItemAmount;
                        if (goldamount < 10000)
                            Item.General[ItemIndex].Pk2ID = 1;
                        else if (goldamount >= 10000 && goldamount <= 500000)
                            Item.General[ItemIndex].Pk2ID = 2;
                        else if (goldamount >= 500001)
                            Item.General[ItemIndex].Pk2ID = 3;

                        Item.General[ItemIndex].UniqueID = (uint)random.Next(76000000, 79999999);
                        Item.General[ItemIndex].Plus = 0;
                        Item.General[ItemIndex].Durability = 0;
                        Item.General[ItemIndex].Pickable = true;
                        Item.General[ItemIndex].Quantity = goldamount;
                        Item.Position[ItemIndex].XSector = Player.Position[Index_].XSector;
                        Item.Position[ItemIndex].YSector = Player.Position[Index_].YSector;
                        randomplace = (byte)random.Next(1, 7);
                        Item.Position[ItemIndex].X = Player.Position[Index_].X + randomplace;
                        Item.Position[ItemIndex].Z = Player.Position[Index_].Z;
                        Item.Position[ItemIndex].Y = Player.Position[Index_].Y + randomplace;
                        Item.General[ItemIndex].DroppedByUniqueId = Player.General[Index_].UniqueID;
                        Item.ItemAmount++;

                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                        if (goldamount < 10000)
                            writer.AppendDword(1);
                        else if (goldamount >= 10000 && goldamount <= 500000)
                            writer.AppendDword(2);
                        else if (goldamount >= 500001)
                            writer.AppendDword(3);
                        writer.AppendDword(goldamount);
                        writer.AppendDword(Item.General[ItemIndex].UniqueID);
                        writer.AppendByte(Item.Position[ItemIndex].XSector);
                        writer.AppendByte(Item.Position[ItemIndex].YSector);
                        writer.AppendFloat(Item.Position[ItemIndex].X);
                        writer.AppendFloat(Item.Position[ItemIndex].X);
                        writer.AppendFloat(Item.Position[ItemIndex].Y);
                        writer.AppendWord(0xDC72);
                        writer.AppendByte(0);
                        writer.AppendByte(0);
                        writer.AppendByte(6);
                        writer.AppendDword(0);

                        tmpBuffer = writer.getWorkspace();

                        for (int i = 0; i < Player.PlayersOnline; i++)
                        {
                            if (Player.General[i].CharacterID != 0)
                            {
                                if (Formula.CalculateDistance(Item.Position[ItemIndex], Player.Position[i]) <= 800)
                                {
                                    ServerSocket.Send(tmpBuffer, i);
                                    Player.Objects[i].SpawnedItemsIndex.Add(ItemIndex);
                                }
                            }
                        }

                        Player.Stats[Index_].Gold -= goldamount;
                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_NEW_GOLD_AMOUNT);
                        writer.AppendByte(1);
                        writer.AppendLword(Player.Stats[Index_].Gold);
                        writer.AppendByte(0);
                        ServerSocket.Send(writer.getWorkspace(), Index_);

                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                        writer.AppendByte(1);
                        writer.AppendByte(10);
                        writer.AppendDword(goldamount);
                        ServerSocket.Send(writer.getWorkspace(), Index_);

                        DatabaseCore.WriteQuery("UPDATE characters SET gold='{0}' WHERE name='{1}'", Player.Stats[Index_].Gold, Player.General[Index_].CharacterName);

                    }
                    break;
            }
        }
Example #2
0
        public static void Action(PacketReader reader_, int Index_)
        {
            PacketWriter writer = new PacketWriter();

            reader_.ModifyIndex(1);
            byte type = reader_.ReadByte();

            if (Player.General[Index_].State != 1)
            {
                switch (type)
                {
                case 1:

                    reader_.ModifyIndex(1);
                    uint ObjectId = reader_.ReadDword();
                    Player.Objects[Index_].AttackingObjectId = ObjectId;
                    int ObjectIndex = Players.GetObjectIndexAndType(Index_, Player.Objects[Index_].AttackingObjectId);

                    bool attack = false;

                    if (Player.Objects[Index_].SelectedObjectType == 2)
                    {
                        attack = Movement.MoveToObject(Index_, ref Player.Position[Index_], Monsters.Position[ObjectIndex], Player.General[Index_], false);
                    }

                    else
                    {
                        attack = Movement.MoveToObject(Index_, ref Player.Position[Index_], Player.Position[ObjectIndex], Player.General[Index_], false);
                    }

                    if (attack)
                    {
                        if (!Player.Objects[Index_].NormalAttack)
                        {
                            Attack.NormalAttack(Index_);
                        }
                    }
                    break;

                case 2:
                    reader_.ModifyIndex(1);
                    ObjectId = reader_.ReadDword();

                    ObjectIndex = 0;
                    for (int i = 0; i <= Item.ItemAmount; i++)
                    {
                        if (Item.General[i].UniqueID == ObjectId && Index_ != i)
                        {
                            ObjectIndex = i;
                            break;
                        }
                    }

                    bool pickup = false;

                    pickup = Movement.MoveToObject(Index_, ref Player.Position[Index_], Item.Position[ObjectIndex], Player.General[Index_], false);

                    if (pickup)
                    {
                        PickUpItem(Index_, ObjectIndex);
                    }

                    break;

                case 4:

                    uint skillid = reader_.ReadDword();

                    bool skillexist          = false;
                    int  CharacterSkillIndex = DatabaseCore.Skill.GetIndexByName(Player.General[Index_].CharacterName);

                    for (int i = 0; i <= DatabaseCore.Skill.SkillAmount[CharacterSkillIndex]; i++)
                    {
                        if (skillid == DatabaseCore.Skill.Skills[CharacterSkillIndex].SkillId[i])
                        {
                            skillexist = true;
                            break;
                        }
                        skillexist = false;
                    }

                    if (skillexist)
                    {
                        byte type_ = reader_.ReadByte();
                        switch (type_)
                        {
                        case 0:
                            bool alreadyactive = false;
                            for (byte i = 0; i < Player.Objects[Index_].ActiveBuffs.Length; i++)
                            {
                                if (Player.Objects[Index_].ActiveBuffs[i].Id == skillid)
                                {
                                    alreadyactive = true;
                                }
                            }
                            if (!alreadyactive)
                            {
                                Player.Objects[Index_].UsingSkillID = skillid;
                                if (!Player.Objects[Index_].UsingSkill)
                                {
                                    PrepareBuff(Index_);
                                }
                            }
                            return;

                        case 1:
                            uint attackingObjectId = reader_.ReadDword();

                            Player.Objects[Index_].AttackingSkillID  = skillid;
                            Player.Objects[Index_].AttackingObjectId = attackingObjectId;
                            Player.Objects[Index_].NormalAttack      = false;
                            if (!Player.Objects[Index_].UsingSkill)
                            {
                                SkillAttackType(Index_);
                            }

                            return;
                        }
                    }
                    break;

                default:
                    Timers.PlayerAttack[Index_].Stop();
                    break;
                }
            }
        }
Example #3
0
        public static unsafe void ProcessData(byte[] buffer, int Index)
        {
            reader = new PacketReader(buffer, buffer.Length);
            reader.ModifyIndex(6);

            TPacket* tmpPacket = Silkroad.ToTPacket(buffer);
            if (debug)
                Console.WriteLine("[ProcessData][{0:X}][{1} bytes][Index {2}]\n{3}\n", tmpPacket->opcode, tmpPacket->size, Index, BitConverter.ToString(buffer, 6, tmpPacket->size).Replace('-', ' '));

            //Console.WriteLine("{0}", tmpPacket->opcode);

            switch (tmpPacket->opcode)
            {
                case CLIENT_OPCODES.GAME_CLIENT_KEEP_ALIVE:
                case CLIENT_OPCODES.GAME_CLIENT_ACCEPT_HANDSHAKE:
                    /*if(debug)
                        Debugx.DumpBuffer(buffer, 1, tmpPacket->opcode, tmpPacket->size);*/
                    //hansh(Index);
                    Auth.SendServerInfo(Index);  //force cliente acept xD
                    break;
                case CLIENT_OPCODES.GAME_CLIENT_INFO:
                    Auth.SendServerInfo(Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_PATCH_REQUEST:
                    Auth.SendPatchInfo(Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_AUTH:
                    Auth.OnAuth(reader,Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_CHARACTER:
                    Character.OnCharacter(reader, Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_INGAME_REQUEST:
                    Character.OnIngameRequest(reader,Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_INGAME_NOTIFY:
                    Players.OnIngameNotify(reader,Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_CHARACTER_STATE:
                    Character.OnState(reader, Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_MOVEMENT:
                    Movement.OnMovement(tmpPacket->data, Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_CLOSE:
                    OnGameQuit(reader,Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_EMOTION:
                    PlayerAction.OnEmotion(reader, Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_ITEM_MOVE:
                    Items.MoveItem(tmpPacket->data,Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_CHAT:
                    Chat.OnChat(reader,Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_TARGET:
                    Players.OnTarget(reader, Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_MASTERYUPDATE :
                    Mastery.OnMasteryUpdate(reader, Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_SKILLUPDATE:
                    Mastery.OnSkillUpdate(reader, Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_STR_UPDATE:
                    Stats.STRUpdate(Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_INT_UPDATE:
                    Stats.INTUpdate(Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_PLAYER_ACTION:
                    PlayerAction.Action(reader, Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_RESPAWN:
                    Character.ReSpawnMe(Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_GM:
                    GameMaster.OnGM(reader,Index);
                    break;

                case CLIENT_OPCODES.GAME_CLIENT_ITEM_USE:
                    Items.OnUseItem(reader, Index);
                    break;

                default:
                    Console.WriteLine("Default Opcode:{0}", tmpPacket->opcode);
                    break;
            }
        }
Example #4
0
        public static void Action(PacketReader reader_, int Index_)
        {
            PacketWriter writer = new PacketWriter();

            reader_.ModifyIndex(1);
            byte type = reader_.ReadByte();

            if (Player.General[Index_].State != 1)
            {
                switch (type)
                {
                    case 1:

                        reader_.ModifyIndex(1);
                        uint ObjectId = reader_.ReadDword();
                        Player.Objects[Index_].AttackingObjectId = ObjectId;
                        int ObjectIndex = Players.GetObjectIndexAndType(Index_, Player.Objects[Index_].AttackingObjectId);

                        bool attack = false;

                        if (Player.Objects[Index_].SelectedObjectType == 2)
                            attack = Movement.MoveToObject(Index_, ref Player.Position[Index_], Monsters.Position[ObjectIndex], Player.General[Index_], false);

                        else
                            attack = Movement.MoveToObject(Index_, ref Player.Position[Index_], Player.Position[ObjectIndex], Player.General[Index_], false);

                        if (attack)
                        {
                            if (!Player.Objects[Index_].NormalAttack)
                                Attack.NormalAttack(Index_);
                        }
                        break;
                    case 2:
                        reader_.ModifyIndex(1);
                        ObjectId = reader_.ReadDword();

                        ObjectIndex = 0;
                        for (int i = 0; i <= Item.ItemAmount; i++)
                        {

                            if (Item.General[i].UniqueID == ObjectId && Index_ != i)
                            {
                                ObjectIndex = i;
                                break;
                            }
                        }

                        bool pickup = false;

                        pickup = Movement.MoveToObject(Index_, ref Player.Position[Index_], Item.Position[ObjectIndex], Player.General[Index_], false);

                        if (pickup)
                            PickUpItem(Index_, ObjectIndex);

                        break;

                    case 4:

                        uint skillid = reader_.ReadDword();

                        bool skillexist = false;
                        int CharacterSkillIndex = DatabaseCore.Skill.GetIndexByName(Player.General[Index_].CharacterName);

                        for (int i = 0; i <= DatabaseCore.Skill.SkillAmount[CharacterSkillIndex]; i++)
                        {
                            if (skillid == DatabaseCore.Skill.Skills[CharacterSkillIndex].SkillId[i])
                            {
                                skillexist = true;
                                break;
                            }
                            skillexist = false;
                        }

                        if (skillexist)
                        {
                            byte type_ = reader_.ReadByte();
                            switch (type_)
                            {
                                case 0:
                                    bool alreadyactive = false;
                                    for (byte i = 0; i < Player.Objects[Index_].ActiveBuffs.Length; i++)
                                    {
                                        if (Player.Objects[Index_].ActiveBuffs[i].Id == skillid)
                                            alreadyactive = true;
                                    }
                                    if (!alreadyactive)
                                    {
                                        Player.Objects[Index_].UsingSkillID = skillid;
                                        if (!Player.Objects[Index_].UsingSkill)
                                            PrepareBuff(Index_);
                                    }
                                    return;

                                case 1:
                                    uint attackingObjectId = reader_.ReadDword();

                                    Player.Objects[Index_].AttackingSkillID = skillid;
                                    Player.Objects[Index_].AttackingObjectId = attackingObjectId;
                                    Player.Objects[Index_].NormalAttack = false;
                                    if (!Player.Objects[Index_].UsingSkill)
                                        SkillAttackType(Index_);

                                    return;
                            }
                        }
                        break;

                    default:
                        Timers.PlayerAttack[Index_].Stop();
                        break;
                }
            }
        }
Example #5
0
        unsafe public static void ProcessData(byte[] buffer, int Index)
        {
            reader = new PacketReader(buffer, buffer.Length);
            reader.ModifyIndex(6);

            TPacket *tmpPacket = Silkroad.ToTPacket(buffer);

            if (debug)
            {
                Console.WriteLine("[ProcessData][{0:X}][{1} bytes][Index {2}]\n{3}\n", tmpPacket->opcode, tmpPacket->size, Index, BitConverter.ToString(buffer, 6, tmpPacket->size).Replace('-', ' '));
            }

            //Console.WriteLine("{0}", tmpPacket->opcode);

            switch (tmpPacket->opcode)
            {
            case CLIENT_OPCODES.GAME_CLIENT_KEEP_ALIVE:
            case CLIENT_OPCODES.GAME_CLIENT_ACCEPT_HANDSHAKE:
                /*if(debug)
                 *  Debugx.DumpBuffer(buffer, 1, tmpPacket->opcode, tmpPacket->size);*/
                //hansh(Index);
                Auth.SendServerInfo(Index);      //force cliente acept xD
                break;

            case CLIENT_OPCODES.GAME_CLIENT_INFO:
                Auth.SendServerInfo(Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_PATCH_REQUEST:
                Auth.SendPatchInfo(Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_AUTH:
                Auth.OnAuth(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_CHARACTER:
                Character.OnCharacter(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_INGAME_REQUEST:
                Character.OnIngameRequest(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_INGAME_NOTIFY:
                Players.OnIngameNotify(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_CHARACTER_STATE:
                Character.OnState(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_MOVEMENT:
                Movement.OnMovement(tmpPacket->data, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_CLOSE:
                OnGameQuit(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_EMOTION:
                PlayerAction.OnEmotion(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_ITEM_MOVE:
                Items.MoveItem(tmpPacket->data, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_CHAT:
                Chat.OnChat(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_TARGET:
                Players.OnTarget(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_MASTERYUPDATE:
                Mastery.OnMasteryUpdate(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_SKILLUPDATE:
                Mastery.OnSkillUpdate(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_STR_UPDATE:
                Stats.STRUpdate(Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_INT_UPDATE:
                Stats.INTUpdate(Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_PLAYER_ACTION:
                PlayerAction.Action(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_RESPAWN:
                Character.ReSpawnMe(Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_GM:
                GameMaster.OnGM(reader, Index);
                break;

            case CLIENT_OPCODES.GAME_CLIENT_ITEM_USE:
                Items.OnUseItem(reader, Index);
                break;

            default:
                Console.WriteLine("Default Opcode:{0}", tmpPacket->opcode);
                break;
            }
        }
Example #6
0
        unsafe public static void MoveItem(byte *ptr, int Index_)
        {
            Silkroad.C_S.MOVE_ITEM *tmpPtr = (Silkroad.C_S.MOVE_ITEM *)ptr;

            PacketWriter writer = new PacketWriter();

            switch (tmpPtr->Type)
            {
            case 0:

                int[]          CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);
                Silkroad.Item_ SourceItem_        = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                Silkroad.Item_ DestinationItem_   = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Destination]]);

                if (SourceItem_.ITEM_TYPE_NAME.Contains("FRPVP_VOUCHER"))
                {
                    if (Player.Stats[Index_].Level >= 10 && CheckItemGender(SourceItem_, Index_))
                    {
                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ANIMATION_CAPE);
                        writer.AppendDword(Player.General[Index_].UniqueID);
                        writer.AppendWord(0x102);
                        writer.AppendByte(0xA);

                        ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);
                        Timers.UsingItemTimer[Index_].Interval      = 10000;
                        Player.Objects[Index_].SourceItemIndex      = CharacterItemIndex[tmpPtr->Source];
                        Player.Objects[Index_].DestinationItemIndex = CharacterItemIndex[tmpPtr->Destination];
                        Timers.UsingItemTimer[Index_].Start();
                    }
                    else
                    {
                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                        writer.AppendWord(0x1002);
                        ServerSocket.Send(writer.getWorkspace(), Index_);
                    }
                }
                else
                {
                    if (tmpPtr->Destination < 13)
                    {
                        if (!SourceItem_.ITEM_TYPE_NAME.Contains("ETC"))
                        {
                            if (!CheckItemGender(SourceItem_, Index_))
                            {
                                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                                writer.AppendWord(0x1602);
                                ServerSocket.Send(writer.getWorkspace(), Index_);
                                return;
                            }
                            else if (!CheckItemLevel(SourceItem_, Index_))
                            {
                                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                                writer.AppendWord(0x1002);
                                ServerSocket.Send(writer.getWorkspace(), Index_);
                                return;
                            }

                            if (tmpPtr->Destination == 6)
                            {
                                Player.General[Index_].WeaponType = SourceItem_.CLASS_C;
                            }

                            Silkroad.Item_ WeaponItem = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[6]]);

                            Console.WriteLine(WeaponItem.CLASS_C);
                            if (tmpPtr->Destination == 6 && DatabaseCore.Item.ItemId[CharacterItemIndex[7]] != 0 && (Player.General[Index_].WeaponType != 2 && Player.General[Index_].WeaponType != 3 && Player.General[Index_].WeaponType != 7 && Player.General[Index_].WeaponType != 10 && Player.General[Index_].WeaponType != 15))
                            {
                                byte unequipped = UnEnquipShield(Index_, CharacterItemIndex, CharacterItemIndex[7]);
                                if (unequipped != 255)
                                {
                                    MoveItemToDatabase(CharacterItemIndex[7], unequipped, Player.General[Index_].CharacterName);
                                }
                            }

                            if (tmpPtr->Destination == 7 && DatabaseCore.Item.ItemId[CharacterItemIndex[6]] != 0 && (WeaponItem.CLASS_C != 2 && WeaponItem.CLASS_C != 3 && WeaponItem.CLASS_C != 7 && WeaponItem.CLASS_C != 10 && WeaponItem.CLASS_C != 15))
                            {
                                byte unequipped = UnEnquipWeapon(Index_, CharacterItemIndex, CharacterItemIndex[6]);
                                if (unequipped != 255)
                                {
                                    MoveItemToDatabase(CharacterItemIndex[6], unequipped, Player.General[Index_].CharacterName);
                                }
                            }

                            EquipItem(Index_, CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination]);
                        }
                        else
                        {
                            if (!(tmpPtr->Destination == 7 && (Player.General[Index_].WeaponType == 6 || Player.General[Index_].WeaponType == 12) && DatabaseCore.Item.ItemId[CharacterItemIndex[7]] != 0))
                            {
                                return;
                            }
                        }
                    }
                    if (tmpPtr->Source < 13)
                    {
                        UnEquipItem(Index_, CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination]);
                    }

                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                    writer.AppendByte(1);
                    writer.AppendByte(tmpPtr->Type);
                    writer.AppendByte(tmpPtr->Source);
                    writer.AppendByte(tmpPtr->Destination);
                    writer.AppendWord(tmpPtr->Amount);
                    writer.AppendByte(0);
                    ServerSocket.Send(writer.getWorkspace(), Index_);

                    MoveItemToDatabase(CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination], Player.General[Index_].CharacterName);
                }
                Stats.OnStatPacket(Index_);
                break;

            case 7:
                CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);

                int ItemIndex = Item.ItemAmount;
                Item.General[ItemIndex].Pk2ID      = DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]];
                Item.General[ItemIndex].UniqueID   = (uint)random.Next(76000000, 79999999);
                Item.General[ItemIndex].Plus       = DatabaseCore.Item.PlusValue[CharacterItemIndex[tmpPtr->Source]];
                Item.General[ItemIndex].Durability = DatabaseCore.Item.Durability[CharacterItemIndex[tmpPtr->Source]];
                Item.General[ItemIndex].Pickable   = true;
                Item.General[ItemIndex].Quantity   = DatabaseCore.Item.Quantity[CharacterItemIndex[tmpPtr->Source]];
                Item.Position[ItemIndex].XSector   = Player.Position[Index_].XSector;
                Item.Position[ItemIndex].YSector   = Player.Position[Index_].YSector;
                byte randomplace = (byte)random.Next(1, 7);
                Item.Position[ItemIndex].X = Player.Position[Index_].X + randomplace;
                Item.Position[ItemIndex].Z = Player.Position[Index_].Z;
                Item.Position[ItemIndex].Y = Player.Position[Index_].Y + randomplace;
                Item.General[ItemIndex].DroppedByUniqueId = Player.General[Index_].UniqueID;
                Item.ItemAmount++;

                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                writer.AppendByte(1);
                writer.AppendByte(tmpPtr->Type);
                writer.AppendByte(tmpPtr->Source);
                ServerSocket.Send(writer.getWorkspace(), Index_);

                Silkroad.Item_ tmpItem = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);

                byte[] tmpBuffer = new byte[0];
                if (tmpItem.ITEM_TYPE_NAME.Contains("CH") || tmpItem.ITEM_TYPE_NAME.Contains("EU"))
                {
                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                    writer.AppendDword(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                    writer.AppendByte(DatabaseCore.Item.PlusValue[CharacterItemIndex[tmpPtr->Source]]);
                    writer.AppendDword(Item.General[ItemIndex].UniqueID);
                    writer.AppendByte(Item.Position[ItemIndex].XSector);
                    writer.AppendByte(Item.Position[ItemIndex].YSector);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].Y);
                    writer.AppendWord(0xAAA6);
                    writer.AppendByte(0);
                    writer.AppendByte(0);
                    writer.AppendByte(6);
                    writer.AppendDword(Item.General[ItemIndex].DroppedByUniqueId);
                    tmpBuffer = writer.getWorkspace();
                }
                else if (tmpItem.ITEM_TYPE_NAME.Contains("ETC"))
                {
                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                    writer.AppendDword(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                    writer.AppendDword(Item.General[ItemIndex].UniqueID);
                    writer.AppendByte(Item.Position[ItemIndex].XSector);
                    writer.AppendByte(Item.Position[ItemIndex].YSector);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].Y);
                    writer.AppendWord(0xAAA6);
                    writer.AppendByte(0);
                    writer.AppendByte(0);
                    writer.AppendByte(6);
                    writer.AppendDword(Item.General[ItemIndex].DroppedByUniqueId);
                    tmpBuffer = writer.getWorkspace();
                }

                for (int i = 0; i < Player.PlayersOnline; i++)
                {
                    if (Player.General[i].CharacterID != 0)
                    {
                        if (Formula.CalculateDistance(Item.Position[ItemIndex], Player.Position[i]) <= 800)
                        {
                            ServerSocket.Send(tmpBuffer, i);
                            Player.Objects[i].SpawnedItemsIndex.Add(ItemIndex);
                        }
                    }
                }

                DatabaseCore.WriteQuery("UPDATE items SET itemid='0',plusvalue='0' ,durability='30' WHERE itemnumber='item{0}' AND owner='{1}'", tmpPtr->Source, Player.General[Index_].CharacterName);
                Stats.OnStatPacket(Index_);

                DeleteFromDatabase(CharacterItemIndex[tmpPtr->Source]);

                break;

            case 10:
                if (Player.Stats[Index_].Gold != 0)
                {
                    PacketReader reader = new PacketReader(ptr, 5);
                    reader.ModifyIndex(1);
                    uint goldamount = reader.ReadDword();


                    ItemIndex = Item.ItemAmount;
                    if (goldamount < 10000)
                    {
                        Item.General[ItemIndex].Pk2ID = 1;
                    }
                    else if (goldamount >= 10000 && goldamount <= 500000)
                    {
                        Item.General[ItemIndex].Pk2ID = 2;
                    }
                    else if (goldamount >= 500001)
                    {
                        Item.General[ItemIndex].Pk2ID = 3;
                    }

                    Item.General[ItemIndex].UniqueID   = (uint)random.Next(76000000, 79999999);
                    Item.General[ItemIndex].Plus       = 0;
                    Item.General[ItemIndex].Durability = 0;
                    Item.General[ItemIndex].Pickable   = true;
                    Item.General[ItemIndex].Quantity   = goldamount;
                    Item.Position[ItemIndex].XSector   = Player.Position[Index_].XSector;
                    Item.Position[ItemIndex].YSector   = Player.Position[Index_].YSector;
                    randomplace = (byte)random.Next(1, 7);
                    Item.Position[ItemIndex].X = Player.Position[Index_].X + randomplace;
                    Item.Position[ItemIndex].Z = Player.Position[Index_].Z;
                    Item.Position[ItemIndex].Y = Player.Position[Index_].Y + randomplace;
                    Item.General[ItemIndex].DroppedByUniqueId = Player.General[Index_].UniqueID;
                    Item.ItemAmount++;

                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                    if (goldamount < 10000)
                    {
                        writer.AppendDword(1);
                    }
                    else if (goldamount >= 10000 && goldamount <= 500000)
                    {
                        writer.AppendDword(2);
                    }
                    else if (goldamount >= 500001)
                    {
                        writer.AppendDword(3);
                    }
                    writer.AppendDword(goldamount);
                    writer.AppendDword(Item.General[ItemIndex].UniqueID);
                    writer.AppendByte(Item.Position[ItemIndex].XSector);
                    writer.AppendByte(Item.Position[ItemIndex].YSector);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].Y);
                    writer.AppendWord(0xDC72);
                    writer.AppendByte(0);
                    writer.AppendByte(0);
                    writer.AppendByte(6);
                    writer.AppendDword(0);

                    tmpBuffer = writer.getWorkspace();

                    for (int i = 0; i < Player.PlayersOnline; i++)
                    {
                        if (Player.General[i].CharacterID != 0)
                        {
                            if (Formula.CalculateDistance(Item.Position[ItemIndex], Player.Position[i]) <= 800)
                            {
                                ServerSocket.Send(tmpBuffer, i);
                                Player.Objects[i].SpawnedItemsIndex.Add(ItemIndex);
                            }
                        }
                    }

                    Player.Stats[Index_].Gold -= goldamount;
                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_NEW_GOLD_AMOUNT);
                    writer.AppendByte(1);
                    writer.AppendLword(Player.Stats[Index_].Gold);
                    writer.AppendByte(0);
                    ServerSocket.Send(writer.getWorkspace(), Index_);


                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                    writer.AppendByte(1);
                    writer.AppendByte(10);
                    writer.AppendDword(goldamount);
                    ServerSocket.Send(writer.getWorkspace(), Index_);

                    DatabaseCore.WriteQuery("UPDATE characters SET gold='{0}' WHERE name='{1}'", Player.Stats[Index_].Gold, Player.General[Index_].CharacterName);
                }
                break;
            }
        }