Exemplo n.º 1
0
        static void AnalyzeDATFile(string path)
        {
            var dat = new DatFile();

            dat.Load(path);

            //TODO: Move save to compilation process
            var fileName = Path.GetFileName(path);

            fileName = Path.ChangeExtension(fileName, "DAT");
            dat.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fileName));
        }
Exemplo n.º 2
0
 void Import(Player p, string fileName, string message, FileType type)
 {
     using (FileStream fs = File.OpenRead(fileName)) {
         try {
             if (type == FileType.Mcf)
             {
                 McfFile.Load(fs, message);
             }
             else if (type == FileType.Fcm)
             {
                 FcmFile.Load(fs, message);
             }
             else
             {
                 DatFile.Load(fs, message);
             }
         } catch (Exception ex) {
             Server.ErrorLog(ex);
             Player.SendMessage(p, "The map conversion failed."); return;
         }
         Player.SendMessage(p, "Converted map!");
         Command.all.Find("load").Use(p, message);
     }
 }
Exemplo n.º 3
0
        public void Start()
        {
            dispatcher = new Dispatcher();

            scheduler = new Scheduler(dispatcher);

            listeners = new List <Listener>();

            listeners.Add(new Listener(7171, socket => new LoginConnection(this, socket)));

            listeners.Add(new Listener(7172, socket => new GameConnection(this, socket)));

            Clock = new Clock(12, 0);

            Logger = new Logger();

            Channels = new ChannelCollection();

            RuleViolations = new RuleViolationCollection();

            PacketsFactory = new PacketsFactory();

            using (Logger.Measure("Loading items", true))
            {
                var otb = OtbFile.Load("data/items/items.otb");

                var dat = DatFile.Load("data/items/tibia.dat");

                var items = ItemsFile.Load("data/items/items.xml");

                ItemFactory = new ItemFactory(otb, dat, items);
            }

            using (Logger.Measure("Loading monsters", true))
            {
                var monsters = MonsterFile.Load("data/monsters");

                MonsterFactory = new MonsterFactory(monsters);
            }

            using (Logger.Measure("Loading npcs", true))
            {
                var npcs = NpcFile.Load("data/npcs");

                NpcFactory = new NpcFactory(npcs);
            }

            using (Logger.Measure("Loading map", true))
            {
                var otbm = OtbmFile.Load("data/map/pholium3.otbm");

                Map = new Map(ItemFactory, otbm);
            }

            Pathfinding = new Pathfinding(Map);

            Events = new EventsCollection();

            Scripts = new ScriptsCollection();

            using (Logger.Measure("Loading scripts", true))
            {
                Scripts.Start(this);
            }

            dispatcher.Start();

            scheduler.Start();

            foreach (var listener in listeners)
            {
                listener.Start();
            }

            Logger.WriteLine("Server online");
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("DAT Tool by CaptainSwag101\n" +
                              "Version 1.0.0, built on 2020-08-03\n");

            if (args.Length == 0)
            {
                Console.WriteLine("ERROR: No targets specified.");
                Console.WriteLine(UsageString);
                return;
            }

            foreach (string arg in args)
            {
                FileInfo info = new FileInfo(arg);
                if (!info.Exists)
                {
                    Console.WriteLine($"ERROR: File \"{arg}\" does not exist, skipping.");
                    continue;
                }

                if (info.Extension.ToLowerInvariant() == ".dat")
                {
                    // Convert DAT to CSV
                    DatFile dat = new DatFile();
                    dat.Load(info.FullName);

                    StringBuilder output = new StringBuilder();

                    // Write first row (header)
                    List <string> headerEntries = new List <string>();
                    foreach (var def in dat.ColumnDefinitions)
                    {
                        headerEntries.Add($"{def.Name} ({def.Type})");
                    }
                    output.AppendJoin(',', headerEntries);
                    output.Append('\n');

                    // Write row data
                    List <string> rowData = new List <string>();
                    for (int row = 0; row < dat.Data.Count; ++row)
                    {
                        StringBuilder rowStr = new StringBuilder();

                        List <string> escapedRowStrs = dat.Data[row];
                        for (int s = 0; s < escapedRowStrs.Count; ++s)
                        {
                            escapedRowStrs[s] = escapedRowStrs[s].Insert(0, "\"").Insert(escapedRowStrs[s].Length + 1, "\"");
                            escapedRowStrs[s] = escapedRowStrs[s].Replace("\n", "\\n").Replace("\r", "\\r");
                        }

                        rowStr.AppendJoin(",", escapedRowStrs);

                        rowData.Add(rowStr.ToString());
                    }
                    output.AppendJoin('\n', rowData);

                    using StreamWriter writer = new StreamWriter(info.FullName.Substring(0, info.FullName.Length - info.Extension.Length) + ".csv", false, Encoding.Unicode);
                    writer.Write(output.ToString());
                }
                else if (info.Extension.ToLowerInvariant() == ".csv")
                {
                    // Convert CSV to DAT
                    DatFile dat = new DatFile();

                    using StreamReader reader = new StreamReader(info.FullName, Encoding.Unicode);

                    // First line is column definitions
                    string[] header         = reader.ReadLine().Split(',');
                    var      colDefinitions = new List <(string Name, string Type, ushort Count)>();
                    foreach (string headerPiece in header)
                    {
                        string name = headerPiece.Split('(').First();
                        string type = headerPiece.Split('(').Last().TrimEnd(')');
                        colDefinitions.Add((name, type, 0));
                    }

                    // Read row data
                    while (!reader.EndOfStream)
                    {
                        string[]      rowCells   = reader.ReadLine().Split(',');
                        List <string> rowStrings = new List <string>();
                        for (int col = 0; col < rowCells.Length; ++col)
                        {
                            // Update the column definitions with the proper value count
                            colDefinitions[col] = (colDefinitions[col].Name, colDefinitions[col].Type, (ushort)(rowCells[col].Count(c => c == '|') + 1));

                            if (rowCells[col].StartsWith('\"'))
                            {
                                rowCells[col] = rowCells[col].Remove(0, 1);
                            }

                            if (rowCells[col].EndsWith('\"'))
                            {
                                rowCells[col] = rowCells[col].Remove(rowCells[col].Length, 1);
                            }

                            rowStrings.Add(rowCells[col].Replace("\\n", "\n").Replace("\\r", "\r"));
                        }
                        dat.Data.Add(rowStrings);
                    }
                    dat.ColumnDefinitions = colDefinitions;

                    dat.Save(info.FullName.Substring(0, info.FullName.Length - info.Extension.Length) + ".dat");
                }
                else
                {
                    Console.WriteLine($"ERROR: Invalid file extension \"{info.Extension}\".");
                    continue;
                }
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("DAT Tool by CaptainSwag101\n" +
                              "Version 0.0.1, built on 2019-10-22\n");

            if (args.Length == 0)
            {
                Console.WriteLine("ERROR: No targets specified.");
                return;
            }

            foreach (string arg in args)
            {
                FileInfo info = new FileInfo(arg);
                if (!info.Exists)
                {
                    Console.WriteLine($"ERROR: File \"{arg}\" does not exist, skipping.");
                    continue;
                }

                if (info.Extension.ToLowerInvariant() == ".dat")
                {
                    // Convert DAT to CSV
                    DatFile dat = new DatFile();
                    dat.Load(info.FullName);

                    StringBuilder output = new StringBuilder();

                    // Write header
                    List <string> headerEntries = new List <string>();
                    foreach (var value in dat.ValueInfo)
                    {
                        headerEntries.Add($"{value.Name} ({value.Type})");
                    }
                    output.AppendJoin(',', headerEntries);
                    output.Append('\n');

                    // Write struct entries
                    List <string> structEntries = new List <string>();
                    foreach (var entry in dat.StructEntries)
                    {
                        StringBuilder combinedEntry = new StringBuilder();
                        combinedEntry.AppendJoin(',', entry);
                        structEntries.Add(combinedEntry.ToString());
                    }
                    output.AppendJoin('\n', structEntries);

                    using StreamWriter writer = new StreamWriter(info.FullName.TrimEnd(info.Extension.ToCharArray()) + ".csv", false);
                    writer.Write(output.ToString());
                }
                else if (info.Extension.ToLowerInvariant() == ".csv")
                {
                    // Convert CSV to DAT
                    DatFile dat = new DatFile();

                    using StreamReader reader = new StreamReader(info.FullName);

                    // First line is header
                    string[] header = reader.ReadLine().Split(',');
                    List <(string Name, string Type)> valInfo = new List <(string Name, string Type)>();
                    foreach (string headerPiece in header)
                    {
                        string name = headerPiece.Split('(').First();
                        string type = headerPiece.Split('(').Last().TrimEnd(')');
                        valInfo.Add((name, type));
                    }
                    dat.ValueInfo = valInfo;

                    // Read struct entries
                    List <List <string> > entries = new List <List <string> >();
                    while (!reader.EndOfStream)
                    {
                        List <string> entry = new List <string>();
                        entry.AddRange(reader.ReadLine().Split(','));
                        entries.Add(entry);
                    }
                    dat.StructEntries = entries;

                    dat.Save(info.FullName.TrimEnd(info.Extension.ToCharArray()) + ".dat");
                }
                else
                {
                    Console.WriteLine($"ERROR: Invalid file extension \"{info.Extension}\".");
                    continue;
                }
            }
        }