示例#1
0
        public void SendEffect(Location location, Effect effect)
        {
            NetworkMessage outMessage = new NetworkMessage();

            EffectPacket.Add(outMessage, location, effect);
            Send(outMessage);
        }
示例#2
0
        public static void addEffect(EffectPacket effectPacket, uint sourceId, string outputFolderName)
        {
            if (!File.Exists(Path.Combine(outputFolderName, $"{sourceId}.mobdef.xml")))
            {
                Console.WriteLine($"    -> Definition file {sourceId}.mobdef.xml not found");
                return;
            }

            try
            {
                XDocument doc = XDocument.Parse(File.ReadAllText(Path.Combine(outputFolderName, $"{sourceId}.mobdef.xml")));

                XElement epEntry = new XElement("EffectPacket");
                epEntry.Add(new XElement("TargetID", effectPacket.targetId));
                epEntry.Add(new XElement("Unknown_1", effectPacket.unknown_1));
                epEntry.Add(new XElement("ActionAnimationID", effectPacket.actionAnimationId));
                epEntry.Add(new XElement("Unknown_2", effectPacket.unknown_2));
                epEntry.Add(new XElement("Unknown_3", effectPacket.unknown_3));
                epEntry.Add(new XElement("ActionTextID", effectPacket.actionTextId));
                epEntry.Add(new XElement("Unknown_5", effectPacket.unknown_5));
                epEntry.Add(new XElement("Unknown_6", effectPacket.unknown_6));
                epEntry.Add(new XElement("Unknown_7", effectPacket.unknown_7));
                epEntry.Add(new XElement("Rotation", effectPacket.rotation));
                epEntry.Add(new XElement("EffectTargetID", effectPacket.effectTargetId));
                epEntry.Add(new XElement("Unknown_10", effectPacket.unknown_10));
                epEntry.Add(new XElement("Unknown_11", effectPacket.unknown_11));

                XElement eEntries = new XElement("EffectEntries");

                foreach (EffectEntry e in effectPacket.effects)
                {
                    XElement thisEffect = new XElement("EffectEntry");

                    thisEffect.Add(new XElement("Unknown_1", e.unknown_1));
                    thisEffect.Add(new XElement("Unknown_2", e.unknown_2));
                    thisEffect.Add(new XElement("Unknown_3", e.unknown_3));
                    thisEffect.Add(new XElement("BonusPercent", e.bonusPercent));
                    thisEffect.Add(new XElement("Param1", e.param1));
                    thisEffect.Add(new XElement("Unknown_5", e.unknown_5));
                    thisEffect.Add(new XElement("Unknown_6", e.unknown_6));

                    eEntries.Add(thisEffect);
                }

                epEntry.Add(eEntries);
                doc.Element("Mob").Element("EffectPackets").Add(epEntry);

                doc.Save(Path.Combine(outputFolderName, $"{sourceId}.mobdef.xml"));
            }catch (Exception exc)
            {
                Console.WriteLine($"    -> writing failed: " + exc);
            }

            Console.WriteLine($"    -> updated {sourceId}.mobdef.xml");
        }
示例#3
0
        public void SendCreatureAppear(Creature creature)
        {
            NetworkMessage message = new NetworkMessage();

            EffectPacket.Add(message, creature.Tile.Location, Effect.Teleport);

            uint remove;
            bool known = IsCreatureKnown(creature.Id, out remove);

            TileAddCreaturePacket.Add(
                message,
                creature.Tile.Location,
                creature.Tile.GetStackPosition(creature),
                creature,
                known,
                remove
                );

            Send(message);
        }
示例#4
0
        private void HandleRecv(SubPacket subpacket)
        {
            //Console.WriteLine("\n-> " + subpacket.gameMessage.opcode.ToString("X"));
            switch (subpacket.gameMessage.opcode)
            {
            /* SERVER OPCODES */

            case 0x111:     /* ACTOR_SPAWN */
                if (Globals.memory)
                {
                    currentZone = Memory.getZoneId();
                }

                Console.WriteLine("\n-> ACTOR_SPAWN");
                ActorSpawnPacket actorSpawnPacket = new ActorSpawnPacket(subpacket.data, currentZone, subpacket.header.sourceId);

                switch (actorSpawnPacket.type)
                {
                case 1:
                    if (actorSpawnPacket.spawnIndex == 0)
                    {
                        Console.WriteLine($"    -> OWN CHARACTER: {actorSpawnPacket.name}   Zone:{currentZone}   EntryLength:{subpacket.data.Length}");
                        //System.Threading.Thread.Sleep(100);

                        /* replaced with init_zone
                         * currentZone = Memory.ReadZoneId();
                         * Console.WriteLine($"    -> New Zone: {currentZone} - {exdreader.GetTerritoryName(currentZone)}");
                         */
                    }
                    else
                    {
                        Console.WriteLine($"    -> CHARACTER: {actorSpawnPacket.name}   Zone:{currentZone}   EntryLength:{subpacket.data.Length}");

                        if (Globals.xmlOutput & Globals.writeChars & currentZone != 0 & !actorSpawnPacket.invalidPacket)
                        {
                            ActorWriter.writeChar(actorSpawnPacket, subpacket.header.sourceId, currentZone, outputFolderName);
                        }
                        else
                        {
                            if (Globals.writeChars)
                            {
                                Console.WriteLine($"    -> currentZone==0(change your zone once to fix) or invalid packet");
                            }
                        }
                    }
                    break;

                case 0:
                    Console.WriteLine($"    -> EMPTY: {actorSpawnPacket.name}   Zone:{currentZone}   EntryLength:{subpacket.data.Length}");
                    break;

                default:
                    Console.WriteLine($"    -> NPC({actorSpawnPacket.nameId}): {Globals.exdreader.GetBnpcName(actorSpawnPacket.nameId)}   Zone:{currentZone}   EntryLength:{subpacket.data.Length}");

                    if (actorSpawnPacket.fateId != 0)
                    {
                        Console.WriteLine($"    -> FATE NPC: {Globals.exdreader.GetFateName(actorSpawnPacket.fateId)}({actorSpawnPacket.fateId})");
                    }

                    if (Globals.UI)
                    {
                        Globals.mapviewform.BeginInvoke((MethodInvoker) delegate() {
                            Globals.mapviewform.addActor(actorSpawnPacket);
                            Globals.mapviewform.invalidateMap();
                        });
                    }

                    //actorSpawnPacket.debugPrintUnknown();
                    //File.WriteAllBytes(Path.Combine(outputFolderName, $"{subpacket.header.sourceId}.dat"), subpacket.data);

                    if (Globals.xmlOutput & currentZone != 0 & !actorSpawnPacket.invalidPacket)
                    {
                        ActorWriter.writeMob(actorSpawnPacket, subpacket.header.sourceId, currentZone, outputFolderName);
                    }
                    else
                    {
                        if (Globals.xmlOutput)
                        {
                            Console.WriteLine($"    -> currentZone==0(change your zone once to fix) or invalid packet");
                        }
                    }

                    if (Globals.csvOutput & currentZone != 0 & !actorSpawnPacket.invalidPacket)
                    {
                        try
                        {
                            ActorWriter.addCSVEntry(actorSpawnPacket, subpacket.header.sourceId, currentZone, Path.Combine("output", outputKey + ".csv"));
                        }catch (Exception exc)
                        {
                            Console.WriteLine($"    -> " + exc);
                        }
                    }
                    else
                    {
                        if (Globals.csvOutput)
                        {
                            Console.WriteLine($"    -> currentZone==0(change your zone once to fix) or invalid packet");
                        }
                    }

                    if (Globals.DB & currentZone != 0 & !actorSpawnPacket.invalidPacket)
                    {
                        using (MySqlCommand command = new MySqlCommand())
                        {
                            command.Connection  = dbconnection;
                            command.CommandText = "INSERT INTO dbbattlenpc (Id, ZoneId, Type, NameId, SizeId, ModelId, ClassJob, DisplayFlags1, DisplayFlags2, Level, Pos_0_0, Pos_0_1, Pos_0_2, Rotation, MobType, Behaviour, ModelMainWeapon, ModelSubWeapon, Look, Models) VALUES (?Id, ?ZoneId, ?Type, ?NameId, ?SizeId, ?ModelId, ?ClassJob, ?DisplayFlags1, ?DisplayFlags2, ?Level, ?Pos_0_0, ?Pos_0_1, ?Pos_0_2, ?Rotation, ?MobType, ?Behaviour, ?ModelMainWeapon, ?ModelSubWeapon, ?Look, ?Models);";
                            List <MySqlParameter> parameters = new List <MySqlParameter>();
                            parameters.Add(new MySqlParameter("?Id", MySqlDbType.Int32, 11));
                            parameters[0].Value = subpacket.header.sourceId;
                            parameters.Add(new MySqlParameter("?ZoneId", MySqlDbType.Int32, 10));
                            parameters[1].Value = currentZone;
                            parameters.Add(new MySqlParameter("?Type", MySqlDbType.Int32, 11));
                            parameters[2].Value = actorSpawnPacket.type;
                            parameters.Add(new MySqlParameter("?NameId", MySqlDbType.Int32, 10));
                            parameters[3].Value = actorSpawnPacket.nameId;
                            parameters.Add(new MySqlParameter("?BnpcBaseId", MySqlDbType.Int32, 10));
                            parameters[4].Value = actorSpawnPacket.bnpcBaseId;
                            parameters.Add(new MySqlParameter("?ModelId", MySqlDbType.Int32, 10));
                            parameters[5].Value = actorSpawnPacket.model;
                            parameters.Add(new MySqlParameter("?ClassJob", MySqlDbType.Int32, 3));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.classJob;
                            parameters.Add(new MySqlParameter("?DisplayFlags", MySqlDbType.Int32, 3));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.displayFlags;
                            parameters.Add(new MySqlParameter("?Level", MySqlDbType.Int32, 3));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.level;
                            parameters.Add(new MySqlParameter("?Pos_0_0", MySqlDbType.Float));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.posx;
                            parameters.Add(new MySqlParameter("?Pos_0_1", MySqlDbType.Float));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.posy;
                            parameters.Add(new MySqlParameter("?Pos_0_2", MySqlDbType.Float));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.posz;
                            parameters.Add(new MySqlParameter("?Rotation", MySqlDbType.Int32, 10));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.rotation;
                            parameters.Add(new MySqlParameter("?MobType", MySqlDbType.Int32, 3));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.mobType;
                            parameters.Add(new MySqlParameter("?Behaviour", MySqlDbType.Int32, 3));
                            parameters[parameters.Count - 1].Value = 0;         //?
                            parameters.Add(new MySqlParameter("?ModelMainWeapon", MySqlDbType.Int32, 20));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.mainWeaponModel;
                            parameters.Add(new MySqlParameter("?ModelSubWeapon", MySqlDbType.Int32, 20));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.secWeaponModel;
                            parameters.Add(new MySqlParameter("?Look", MySqlDbType.Blob, actorSpawnPacket.lookdata.Length));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.lookdata;
                            parameters.Add(new MySqlParameter("?Models", MySqlDbType.Blob, actorSpawnPacket.models.Length));
                            parameters[parameters.Count - 1].Value = actorSpawnPacket.models;

                            foreach (MySqlParameter parameter in parameters)
                            {
                                command.Parameters.Add(parameter);
                            }

                            try
                            {
                                command.Prepare();
                                command.ExecuteNonQuery();
                                Console.WriteLine(command.CommandText);
                            }catch (Exception exc)
                            {
                                Console.WriteLine($"    -> Error writing to DB: " + exc.Message);
                            }
                        }
                    }
                    else
                    {
                        if (Globals.DB)
                        {
                            Console.WriteLine($"    -> currentZone==0(change your zone once to fix) or invalid packet");
                        }
                    }
                    break;
                }
                break;

            case 0x19A:     /* INIT_ZONE */
                Console.WriteLine("\n-> INIT_ZONE");
                InitZonePacket initZonePacket = new InitZonePacket(subpacket.data);

                currentZone = Convert.ToInt32(initZonePacket.zoneId);

                if (Globals.UI)
                {
                    Globals.mapviewform.BeginInvoke((MethodInvoker) delegate() { Globals.mapviewform.SetMapWithId(currentZone, 00); });
                }

                Console.WriteLine($"    -> New Zone({initZonePacket.zoneId}): {Globals.exdreader.GetTerritoryName(currentZone)}      EntryLength:{subpacket.data.Length}");
                break;

            case 0x146:     /* EFFECT */
                Console.WriteLine("\n-> EFFECT");
                EffectPacket effectPacket = new EffectPacket(subpacket.data);

                Console.WriteLine($"    -> ACTION: {Globals.exdreader.GetActionName((int)effectPacket.actionTextId)}   SourceId:{subpacket.header.sourceId}   TargetId:{subpacket.header.targetId}   Zone:{currentZone}   EntryLength:{subpacket.data.Length}");

                if (Globals.xmlOutput)
                {
                    ActorWriter.addEffect(effectPacket, subpacket.header.sourceId, outputFolderName);
                }

                break;
            }
        }
示例#5
0
        public void SendInitialPacket()
        {
            NetworkMessage message = new NetworkMessage();

            SelfAppearPacket.Add(
                message,
                Player.Id,
                true
                );

            MapDescriptionPacket.Add(
                this,
                message,
                Player.Tile.Location
                );

            EffectPacket.Add(message, Player.Tile.Location, Effect.Teleport);

            foreach (var kvp in Player.Inventory.GetSlotItems())
            {
                InventorySetSlotPacket.Add(
                    message,
                    kvp.Key,
                    kvp.Value
                    );
            }

            WorldLightPacket.Add(
                message,
                LightLevel.World,
                LightColor.White
                );

            CreatureLightPacket.Add(
                message,
                Player.Id,
                LightLevel.None,
                LightColor.None
                );

            string welcomeMessage = String.Format(
                Settings.Default.WelcomeMessage,
                Settings.Default.WorldName,
                Player.Name);

            if (Player.LastLogin > DateTime.MinValue)
            {
                welcomeMessage += String.Format(" Last login: {0}.", Player.LastLogin);
            }
            TextMessagePacket.Add(
                message,
                TextMessageType.EventDefault,
                welcomeMessage
                );

            PlayerStatusPacket.Add(
                message,
                Player.Health,
                Player.MaxHealth,
                Player.Capacity,
                Player.Experience,
                Player.Level,
                0, // TODO: level system
                Player.Mana,
                Player.MaxMana,
                Player.MagicLevel,
                0,
                0,
                0
                );

            // Player skills
            //message.AddBytes("A1 0A 02 0A 00 0E 44 0B 62 0A 0D 0F 3E 13 26".ToBytesAsHex());

            // Fight modes
            //message.AddBytes("A0 02 00 01".ToBytesAsHex());

            Send(message);
        }