Beispiel #1
0
        public static void OnCreateNewCharacter(MapleClient c, InPacket p)
        {
            string name = p.ReadMapleString();

            if (Database.Instance.NameAvailable(name))
            {
                Character character = new Character(name);
                character.AccountId = c.Account.AccountId;
                character.CharId    = Database.Instance.GetNewCharacterId();
                character.Level     = 1;

                character.HP    = 50;
                character.MaxHP = 50;
                character.MP    = 5;
                character.MaxMP = 5;

                character.Face      = p.ReadInt();
                character.Hair      = p.ReadInt() + p.ReadInt();
                character.SkinColor = (byte)p.ReadInt();

                int top    = p.ReadInt();
                int bottom = p.ReadInt();
                int shoes  = p.ReadInt();
                int weapon = p.ReadInt();

                character.Inventory[InventorySlot.Equipped].Items.Add(-5, new Item(top));
                character.Inventory[InventorySlot.Equipped].Items.Add(-6, new Item(bottom));
                character.Inventory[InventorySlot.Equipped].Items.Add(-7, new Item(shoes));
                character.Inventory[InventorySlot.Equipped].Items.Add(-11, new Item(weapon));

                character.Str = p.ReadByte();
                character.Dex = p.ReadByte();
                character.Int = p.ReadByte();
                character.Luk = p.ReadByte();

                c.Characters.Add(character);
                Database.Instance.Save <Character>(Database.Characters, character);

                using (OutPacket packet = new OutPacket(SendOps.CreateNewCharacterResult))
                {
                    packet.WriteByte();

                    PacketCreator.Helper.AddCharacterData(packet, character);
                    PacketCreator.Helper.AddCharaterLook(packet, character);
                    packet.WriteBool(false); //rank

                    packet.WriteZero(24);
                    c.Send(packet);
                }
            }
            else
            {
                using (OutPacket packet = new OutPacket(SendOps.CheckDuplicatedIDResult))
                {
                    packet.WriteMapleString(name);
                    packet.WriteBool(true);
                    c.Send(packet);
                }
            }
        }
Beispiel #2
0
 public static void AddCharacterData(OutPacket p, Character c)
 {
     p.WriteInt(c.CharId);
     p.WritePaddedString(c.Name, 13);
     p.WriteByte(c.Gender);
     p.WriteByte(c.SkinColor);
     p.WriteInt(c.Face);
     p.WriteInt(c.Hair);
     p.WriteLong(); //pet
     p.WriteByte(c.Level);
     p.WriteShort(c.Job);
     p.WriteShort(c.Str);
     p.WriteShort(c.Dex);
     p.WriteShort(c.Int);
     p.WriteShort(c.Luk);
     p.WriteShort(c.HP);
     p.WriteShort(c.MaxHP);
     p.WriteShort(c.MP);
     p.WriteShort(c.MaxMP);
     p.WriteShort(c.AP);
     p.WriteShort(c.SP);
     p.WriteInt(c.EXP);
     p.WriteShort(c.Fame);
     p.WriteInt(c.MapId);
     p.WriteByte(c.SpawnPoint);
     p.WriteZero(16);
 }
Beispiel #3
0
        public byte[] getInitialPacket()
        {
            OutPacket p = new OutPacket(608);

            p.WriteInt(608);
            p.WriteShort(0x05);
            p.WriteShort(0x03);
            p.WriteInt(0x02);
            p.WriteInt(uID);
            p.WriteZero(48);
            p.WriteInt(this.mController.getData().getmID());
            p.WriteInt();
            p.WriteInt(curHP);
            p.WriteZero(8);
            p.WriteFloat(positionX);
            p.WriteFloat(positionY);
            //Console.WriteLine("mobid {0} mobuid {1} xcord {2} ycord {3} hp {4}", this.mController.getData().getmID(), uID, positionX, positionY, curHP);
            return(p.ToArray());
        }
Beispiel #4
0
        public static void OnSelectWorld(MapleClient c, InPacket p)
        {
            p.Skip(1); // world id
            c.Channel = p.ReadByte();

            using (OutPacket packet = new OutPacket(SendOps.SelectWorldResult))
            {
                packet.WriteByte(); //some error

                packet.WriteByte((byte)c.Characters.Count);

                foreach (var character in c.Characters)
                {
                    PacketCreator.Helper.AddCharacterData(packet, character);
                    PacketCreator.Helper.AddCharaterLook(packet, character);
                    packet.WriteBool(false); //rank
                }

                packet.WriteZero(64); //padding
                c.Send(packet);
            }
        }
Beispiel #5
0
        public static void BuyFromNPC(MartialClient c, InPacket p)
        {
            if (c.getAccount().activeCharacter == null)
            {
                Logger.LogCheat(Logger.HackTypes.CreateCharacter, c, "Attempted to hook a NPC open while not being ingame.");
                c.Close();
                return;
            }

            Character chr = c.getAccount().activeCharacter;

            byte[] decrypted = p.ReadBytes(9);

            int npcID = BitConverter.ToInt32(decrypted, 0);

            if (WMap.Instance.getNpcs().ElementAtOrDefault(npcID) == null)
            {
                Logger.LogCheat(Logger.HackTypes.NPC, c, "Tried to hook NPC of uID {0}", npcID);
                return;
            }

            NPC npc = WMap.Instance.getNpcs()[npcID];

            OutPacket op = new OutPacket(56);

            op.WriteInt(56);
            op.WriteShort(4);
            op.WriteShort(19);
            op.WriteInt(1);
            op.WriteInt(c.getAccount().activeCharacter.getuID());

            if (decrypted[8] != 0)
            {
                int itemID = NPCDataCache.Instance.getNPCDataByuID(npcID, chr.getMap()).getItemFromSlot(decrypted[4]);
                if (itemID == -1)
                {
                    Console.WriteLine("Somebody tried to buy not existing item");
                    return;
                }

                ItemData itemData = ItemDataCache.Instance.getItemData(itemID);
                if (itemData == null)
                {
                    Console.WriteLine("Tried to buy not existing item");
                    return;
                }

                Item item = new Item(itemID, decrypted[8]);

                int itemPrice = 0;
                if (payedItems.Contains(itemData.getID()))
                {
                    itemPrice = itemData.getNpcPrice() * decrypted[8];
                    if (chr.getCoin() < itemPrice)
                    {
                        Console.WriteLine("Tried to buy free Gold Bars :3");
                        return;
                    }
                }

                Console.WriteLine("line {0} row {1}", decrypted[7], decrypted[6]);
                if (!chr.getInventory().buyItem(item, decrypted[7], decrypted[6]))
                {
                    Console.WriteLine("npc.. something went wrong");
                    return;
                }

                chr.setCoin(chr.getCoin() - itemPrice);

                op.WriteLong(chr.getCoin());
                op.WriteShort(0x01);
                op.WriteByte(decrypted[5]);
                op.WriteByte(decrypted[6]);
                op.WriteByte(decrypted[7]);
                op.WriteByte(chr.getVp());                 // vending points (?)
                op.WriteZero(18);
                op.WriteInt(itemID);
                op.WriteByte(decrypted[8]);
            }
            else
            {
                op.WriteInt(npcID);
                op.WriteInt();
                op.WriteInt(0x01);
                op.WriteInt();
                op.WriteInt();
                op.WriteInt(0);                 // -100% extra charge => free buying
                op.WriteInt(8388608);           // -100% discount => free selling
                op.WriteByte(0x80);
                op.WriteByte(0x3f);
                //op.WriteLong(1294138); // looks like.. areaID? for sure not modelID, or other shit, just the second short looks familiar
                //op.WriteLong(1); // must be 1 to open the shop o.o
                //op.WriteInt(64); // 0% ?
                //op.WriteInt(1065353216); // -100% extra charge => free buying
                //op.WriteInt(1065353216); // -100% discount => free selling

                /* IN TWO WORDS -> WEIRD SHIT HERE */
            }

            c.WriteRawPacket(op.ToArray());
        }
Beispiel #6
0
        public static void OnCheckPassword(MapleClient c, InPacket p)
        {
            string user = p.ReadMapleString().Trim();
            string pass = p.ReadMapleString();

            //byte[] machineId = p.ReadBytes(0x10);
            //int gameRoomCode = p.ReadInt();
            //byte gameStartMode = p.ReadByte();
            //bool adminClient = p.ReadBool();

            byte loginResult = MasterServer.Instance.LoginClient(c, user, pass);

            using (OutPacket packet = new OutPacket(SendOps.CheckPasswordResult))
            {
                packet.WriteByte(loginResult);
                packet.WriteZero(5); //v11 (1) + v12 (4)

                if (loginResult == 0)
                {
                    packet.WriteInt(c.Account.AccountId);
                    packet.WriteByte();
                    packet.WriteBool(c.Account.GM);
                    packet.WriteByte(1);
                    packet.WriteMapleString(c.Account.Username);
                    packet.WriteZero(12);
                }
                else if (loginResult == 2) //TODO : Add packet for this
                {
                    c.Close();
                    return;
                }

                packet.WriteZero(24); //padding
                c.Send(packet);
            }

            if (loginResult != 0)
            {
                return;
            }

            using (OutPacket packet = new OutPacket(SendOps.CheckUserLimitResult, 3))
            {
                packet.WriteByte(4);
                c.Send(packet);
            }

            using (OutPacket packet = new OutPacket(SendOps.WorldInformation))
            {
                byte   worldId = 0;
                string name    = Constants.WorldName;

                packet.WriteByte(worldId);
                packet.WriteMapleString(name);

                packet.WriteByte((byte)MasterServer.Instance.Channels.Length);

                int id = 1;

                foreach (var ch in MasterServer.Instance.Channels)
                {
                    packet.WriteMapleString("{0}-{1}", name, id++);
                    packet.WriteInt(ch.Load);
                    packet.WriteByte(worldId);
                    packet.WriteByte((byte)(id - 1));
                    packet.WriteByte(0x00);
                }

                c.Send(packet);
            }

            using (OutPacket packet = new OutPacket(SendOps.WorldInformation, 3))
            {
                packet.WriteByte(0xff);
                c.Send(packet);
            }
        }
        public static void setPlayerPosition(Character chr, float goX, float goY, short map)
        {
            MartialClient c = chr.getAccount().mClient;

            Logger.WriteLog(Logger.LogTypes.Debug, goX + " | " + goY + " | " + map);

            Area lastArea = chr.getArea();
            Area newArea  = WMap.Instance.getGrid(map).getAreaByRound(goX, goY);

            if (newArea == null)
            {
                StaticPackets.sendSystemMessageToClient(chr.getAccount().mClient, 1, "The position " + goX + "|" + goY + "|" + map + " can't be reached.");
                Waypoint closestTown = TownCoordsCache.Instance.getClosestWaypointForMap(map, new Waypoint(goX, goY));
                if (closestTown == null)
                {
                    Area vvArea = WMap.Instance.getGrid(1).getAreaByRound(-1660, 2344);
                    if (vvArea == null)
                    {
                        Logger.WriteLog(Logger.LogTypes.Error, "Pure setPlayerPosition error {0}|{1}|{2}", goX, goY, map);
                        StaticPackets.sendSystemMessageToClient(chr.getAccount().mClient, 1, "We're sorry, but an hard error has occured. Please report it to an admin.");
                        c.Close();
                        return;
                    }
                    else
                    {
                        goX     = -1660;
                        goY     = 2344;
                        map     = 1;
                        newArea = vvArea;
                    }
                }
                else
                {
                    goX     = closestTown.getX();
                    goY     = closestTown.getY();
                    newArea = WMap.Instance.getGrid(map).getAreaByRound(goX, goY);
                }
            }

            if (lastArea != null)
            {
                WMap.Instance.getGrid(chr.getMap()).sendTo3x3AreaLeave(chr, lastArea);
                lastArea.removeCharacter(chr);
            }

            if (newArea != null)
            {
                chr.setArea(newArea);
            }
            else
            {
                chr.getAccount().mClient.Close();
                return;
            }

            newArea.addCharacter(chr);

            chr.setMap(map);
            chr.setPosition(new float[] { goX, goY });

            OutPacket op = new OutPacket(5840);

            op.WriteInt(5824);
            op.WriteShort(4);                                                          // 4 - 5
            op.WriteShort(1);                                                          // 6 - 7
            op.WriteInt(1);                                                            // 8 - 11
            op.WriteInt(chr.getuID());                                                 // 12 - 15
            op.WriteShort(1);                                                          // 16 - 19
            op.WriteShort(1);                                                          // 16 - 19
            op.WriteInt(chr.getMap());                                                 // 20 - 23
            op.WriteInt(DateTime.Now.Year - 2000);                                     // 24 - 27
            op.WriteByte((byte)DateTime.Now.Month);                                    // 28
            op.WriteByte(DateTime.Now.Day > 30 ? (byte)0x1e : (byte)DateTime.Now.Day); // 29
            op.WriteInt(DateTime.Now.Hour);                                            // 30 - 37

            for (int i = 0; i < 120; i++)
            {
                if (chr.getCargo().getSeqSaved()[i] != -1 && chr.getCargo().getCargoSaved()[chr.getCargo().getSeqSaved()[i]] != null)
                {
                    op.WriteInt();
                    op.WriteByte((byte)(chr.getCargo().getSeqSaved()[i] / 100));
                    op.WriteByte((byte)(chr.getCargo().getSeqSaved()[i] % 100));
                    Item item = chr.getCargo().getCargoSaved()[chr.getCargo().getSeqSaved()[i]];
                    op.WriteInt(item.getItemID());
                    ItemData itemData = ItemDataCache.Instance.getItemData(item.getItemID());
                    if (itemData.getTimeToExpire() > 0)
                    {
                    }
                    op.WriteShort(item.getQuantity());
                }
                else
                {
                    op.WriteZero(12);
                }
            }             // 38 - 1477

            op.Position = 1476;

            for (int i = 0; i < chr.getCommunity().getFriendsList().Capacity; i++)
            {
                if (chr.getCommunity().getFriendsList().ElementAtOrDefault(i) != null)
                {
                    op.WritePaddedString(chr.getCommunity().getFriendsList()[i], 17);
                }
                else
                {
                    op.WriteZero(17);
                }
            }             // 1476 - 1934

            op.WriteRepeatedByte(0x58, 40);

            op.Position = 1986;

            for (int i = 0; i < chr.getCommunity().getIgnoresList().Capacity; i++)
            {
                if (chr.getCommunity().getIgnoresList().ElementAtOrDefault(i) != null)
                {
                    op.WritePaddedString(chr.getCommunity().getIgnoresList()[i], 17);
                }
                else
                {
                    op.WriteZero(17);
                }
            }                 // 1987 - 2157

            op.WriteInt(363); // questsy
            op.WriteLong();
            op.WriteLong(138769276674441706);
            op.WriteLong(21692910);
            op.WriteShort();
            op.WriteShort(1);

            op.Position = 2248;

            for (byte i = 0; i < 240; i++)
            {
                if (chr.getInventory().getSeqSaved()[i] != -1 && chr.getInventory().getInvSaved()[chr.getInventory().getSeqSaved()[i]] != null)
                {
                    op.WriteShort();
                    op.WriteByte((byte)(chr.getInventory().getSeqSaved()[i] / 100));
                    op.WriteByte((byte)(chr.getInventory().getSeqSaved()[i] % 100));
                    Item item = chr.getInventory().getInvSaved()[chr.getInventory().getSeqSaved()[i]];
                    op.WriteInt(item.getItemID());
                    op.WriteInt(item.getQuantity());
                }
                else
                {
                    op.WriteZero(12);
                }
            }             // 2252 - 5133

            op.WriteLong(chr.getCoin());

            op.Position = 5140;

            for (byte i = 0; i < 21; i++)
            {
                if (chr.getSkillBar().getSkillBar().ContainsKey(i))
                {
                    int barID = chr.getSkillBar().getSkillBar()[i];
                    if (barID > 200000000)
                    {
                        op.WriteInt(1);
                    }
                    else if (barID > 511)
                    {
                        op.WriteInt(5); barID -= 512;
                    }
                    else if (barID > 255)
                    {
                        op.WriteInt(6); barID -= 256;
                    }
                    else
                    {
                        SkillData skill = SkillDataCache.Instance.getSkill(chr.getSkills().getLearnedSkills().ElementAtOrDefault(barID));
                        if (skill == null)
                        {
                            op.WriteInt(0);
                        }
                        else if (skill.getTypeSpecific() == 6)
                        {
                            op.WriteInt(3);
                        }
                        else if (skill.getTypeSpecific() == 7)
                        {
                            op.WriteInt(4);
                        }
                        else
                        {
                            op.WriteInt(2);
                        }
                    }
                    op.WriteInt(barID);
                }
                else
                {
                    op.WriteZero(8);
                }
            }             // 5140 - 5299

            op.Position = 5320;

            for (int i = 0; i < 60; i++)
            {
                if (chr.getSkills().getLearnedSkills().Count > i && chr.getSkills().getLearnedSkills()[i] != 0)
                {
                    op.WriteInt(chr.getSkills().getLearnedSkills()[i]);
                    op.WriteInt(SkillDataCache.Instance.getSkill(chr.getSkills().getLearnedSkills()[i]).getSkillPoints());
                }
                else
                {
                    op.WriteLong();
                }
            }             // 5320 - 5799

            op.WriteFloat(chr.getPosition()[0]);
            op.WriteFloat(chr.getPosition()[1]);
            op.WriteInt(0x0c);
            op.WriteInt(140338688);
            op.WriteInt();
            op.WriteShort();
            op.WriteShort(10962);

            //s3c0nd p4ck3t
            op.WriteInt(16);
            op.WriteInt(7929861);
            op.WriteInt(chr.getuID());
            c.WriteRawPacket(op.ToArray());

            WMap.Instance.getGrid(chr.getMap()).sendTo3x3AreaSpawn(chr, chr.getArea());
        }