public static void DbItemsBuyingStore <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                IntLineStream lines = new IntLineStream(db.UsePreviousOutput ? debug.FilePath : debug.OldPath);
                lines.Remove(db);
                string line;

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    bool item1 = tuple.GetValue <bool>(ServerItemAttributes.BuyingStore);

                    if (!item1)
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = key.ToString(CultureInfo.InvariantCulture) + "  // " + tuple.GetValue <string>(ServerItemAttributes.AegisName);
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
        public static void DbItemsStack <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                IntLineStream lines = new IntLineStream(db.UsePreviousOutput ? debug.FilePath : debug.OldPath);
                lines.Remove(db);
                string line;

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    string item1 = tuple.GetValue <string>(ServerItemAttributes.Stack);

                    if (item1 == "")
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = string.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture), item1 }.ToArray());
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Beispiel #3
0
        public static void DbAttachLuaLoader <T>(DbDebugItem <T> debug, string tableName, string path)
        {
            try {
                var db   = debug.AbsractDb;
                var data = debug.AbsractDb.ProjectDatabase.MetaGrf.GetData(path);

                if (data == null)
                {
                    db.Attached[tableName]        = null;
                    db.Attached[tableName + "_T"] = null;
                    return;
                }

                LuaParser parser = new LuaParser(data, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(data), EncodingService.DisplayEncoding);

                try {
                    var luaTable = parser.Tables[tableName];
                    Dictionary <string, string> dico = new Dictionary <string, string>();
                    foreach (var pair in luaTable)
                    {
                        dico[pair.Key.Trim('[', ']', '\"')] = pair.Value;
                    }
                    parser.Tables[tableName]      = dico;
                    db.Attached[tableName]        = parser;
                    db.Attached[tableName + "_T"] = dico;
                }
                catch {
                    db.Attached[tableName] = null;
                }
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Beispiel #4
0
        public static void DbDirectCopyWriter <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                if (debug.OldPath != debug.FilePath)
                {
                    var storeCompareList = db.Attached["StoreCompare"] as List <string>;

                    if (storeCompareList != null)
                    {
                        foreach (var path in storeCompareList)
                        {
                            var oldPath = DbPathLocator.GetStoredFile(path);

                            if (!IOHelper.SameFile(oldPath, path))
                            {
                                // Test their modified date
                                IOHelper.Delete(path);
                                IOHelper.Copy(oldPath, path);
                            }
                        }
                    }
                    else if (!IOHelper.SameFile(debug.OldPath, debug.FilePath))
                    {
                        // Test their modified date
                        IOHelper.Delete(debug.FilePath);
                        IOHelper.Copy(debug.OldPath, debug.FilePath);
                    }
                }
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
        public static void DbConstantsWriter <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                StringLineStream lines = new StringLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    string key = tuple.GetKey <string>();

                    int item2 = tuple.GetValue <int>(2);

                    if (item2 == 0)
                    {
                        line = string.Join("\t", tuple.GetRawElements().Take(2).Select(p => (p ?? "").ToString()).ToArray());
                    }
                    else
                    {
                        line = string.Join("\t", tuple.GetRawElements().Take(3).Select(p => (p ?? "").ToString()).ToArray());
                    }

                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
        public static void Writer(DbDebugItem <int> debug, AbstractDb <int> db)
        {
            var    gdb      = db.ProjectDatabase;
            string filename = ProjectConfiguration.ClientCheevo;

            if (gdb.MetaGrf.GetData(filename) == null)
            {
                Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CItems, filename, null, "Achievement table not saved."));
                return;
            }

            BackupEngine.Instance.BackupClient(filename, gdb.MetaGrf);

            StringBuilder builder = new StringBuilder();

            builder.AppendLine("achievement_tbl = {");

            List <ReadableTuple <int> > tuples = gdb.GetDb <int>(ServerDbs.CCheevo).Table.GetSortedItems().ToList();
            ReadableTuple <int>         tuple;

            for (int index = 0, count = tuples.Count; index < count; index++)
            {
                tuple = tuples[index];
                WriteEntry(builder, tuple, index == count - 1);
            }

            builder.AppendLine("}");
            builder.AppendLine();
            builder.AppendLine(ResourceString.Get("AchievementFunction"));

            gdb.MetaGrf.SetData(filename, EncodingService.Ansi.GetBytes(builder.ToString()));

            Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CItems, gdb.MetaGrf.FindTkPath(filename), null, "Saving Achievement table."));
        }
        public static void DbItemsNouse <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                IntLineStream lines = new IntLineStream(db.UsePreviousOutput ? debug.FilePath : debug.OldPath);
                lines.Remove(db);
                string line;
                NoUse  nouse = new NoUse();

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    string item1 = tuple.GetValue <string>(ServerItemAttributes.NoUse);
                    nouse.Override = ParserHelper.GetVal(item1, "override", "100");
                    nouse.Sitting  = ParserHelper.GetVal(item1, "sitting", "false");

                    if (nouse.Override == "100" && nouse.Sitting == "false")
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = string.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture), nouse.Sitting == "true" ? "1" : "0", nouse.Override }.ToArray());
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Beispiel #8
0
        public static void DbItemsStack <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                TkDictionary <TKey, string[]> phantom = _getPhantomTable(debug);

                if (phantom != null)
                {
                    var itemDb = debug.AbsractDb.GetDb <TKey>(ServerDbs.Items).Table;

                    // Check if the phantom values differ from the Items1
                    foreach (var tuple in phantom)
                    {
                        if (debug.AbsractDb.Table.ContainsKey(tuple.Key))
                        {
                            continue;
                        }

                        var key      = tuple.Key;
                        var elements = tuple.Value;
                        var tuple1   = itemDb.TryGetTuple(key);

                        if (tuple1 != null)
                        {
                            string val1 = tuple1.GetValue <string>(ServerItemAttributes.Stack);
                            string val2 = elements[1];

                            if (val1 != val2)
                            {
                                lines.Delete(tuple1.GetKey <int>());
                            }
                        }
                    }
                }

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    string item1 = tuple.GetValue <string>(ServerItemAttributes.Stack);

                    if (item1 == "")
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = String.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture), item1 }.ToArray());
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Beispiel #9
0
        public static void Loader(DbDebugItem <int> debug, AbstractDb <int> db)
        {
            if (ProjectConfiguration.UseLuaFiles)
            {
                LoadEntry(db, ProjectConfiguration.ClientItemInfo);
                _loadCardIllustrationNames(db, db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.ClientCardIllustration));
                _loadCardPrefixes(db, db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.ClientCardPrefixes));
                _loadCardPostfixes(db, db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.ClientCardPostfixes));
            }
            else
            {
                _loadCardIllustrationNames(db, db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.ClientCardIllustration));
                _loadCardPrefixes(db, db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.ClientCardPrefixes));
                _loadCardPostfixes(db, db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.ClientCardPostfixes));

                _loadData(db, ProjectConfiguration.ClientItemSlotCount, ClientItemAttributes.NumberOfSlots);
                _loadData(db, ProjectConfiguration.ClientItemIdentifiedName, ClientItemAttributes.IdentifiedDisplayName, false, true);
                _loadData(db, ProjectConfiguration.ClientItemUnidentifiedName, ClientItemAttributes.UnidentifiedDisplayName, false, true);
                _loadData(db, ProjectConfiguration.ClientItemIdentifiedResourceName, ClientItemAttributes.IdentifiedResourceName, false);
                _loadData(db, ProjectConfiguration.ClientItemUnidentifiedResourceName, ClientItemAttributes.UnidentifiedResourceName, false);
                _loadData(db, ProjectConfiguration.ClientItemIdentifiedDescription, ClientItemAttributes.IdentifiedDescription);
                _loadData(db, ProjectConfiguration.ClientItemUnidentifiedDescription, ClientItemAttributes.UnidentifiedDescription);
                _loadViewId(db);
            }
        }
Beispiel #10
0
        public static void DbIOWriterConf <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, DbIOWriteEntryMethod <TKey> writeEntryMethod)
        {
            try {
                if (debug.FileType == FileType.Conf)
                {
                    try {
                        var lines = new LibconfigParser(debug.OldPath, LibconfigMode.Write);
                        lines.Remove(db);

                        foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                        {
                            string key = tuple.Key.ToString();

                            StringBuilder builder = new StringBuilder();
                            writeEntryMethod(builder, tuple);
                            lines.Write(key, builder.ToString());
                        }

                        lines.WriteFile(debug.FilePath);
                    }
                    catch (Exception err) {
                        debug.ReportException(err);
                    }
                }
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Beispiel #11
0
        public static void DbLuaLoader <T>(DbDebugItem <T> debug,
                                           DbAttribute attribute, string tableName, int tableId, Func <string> getPath,
                                           Func <string, T> getId, Func <string, string> getValue)
        {
            try {
                var table = debug.AbsractDb.Table;

                var data = debug.AbsractDb.ProjectDatabase.MetaGrf.GetData(getPath());

                if (data == null)
                {
                    return;
                }
                LuaParser parser = new LuaParser(data, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(data), EncodingService.DisplayEncoding);

                var luaTable = parser.Tables[tableName];

                foreach (var pair in luaTable)
                {
                    T id = getId(pair.Key);

                    if (id.Equals(default(T)))
                    {
                        continue;
                    }
                    table.SetRaw(id, attribute, getValue(pair.Value));
                }
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Beispiel #12
0
        public static void DbCommaNoCast <T>(DbDebugItem <T> debug, AttributeList list, int indexStart, int length)
        {
            var table = debug.AbsractDb.Table;

            foreach (string[] elements in TextFileHelper.GetElementsByCommas(File.ReadAllBytes(debug.FilePath)))
            {
                try {
                    T   itemId = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);
                    int max    = length;

                    for (int index = 1; index < elements.Length && max > 0; index++)
                    {
                        DbAttribute property = list.Attributes[index + indexStart - 1];

                        int previousVal = 0;

                        if (table.ContainsKey(itemId))
                        {
                            previousVal = table.GetTuple(itemId).GetValue <int>(ServerSkillAttributes.Flag);
                        }

                        table.SetRaw(itemId, property, Int32.Parse(elements[index]) | previousVal);
                        max--;
                    }
                }
                catch (Exception err) {
                    if (!debug.ReportException(err))
                    {
                        return;
                    }
                }
            }
        }
Beispiel #13
0
        public static void DbSqlMobSkills(DbDebugItem <string> debug, AbstractDb <string> db)
        {
            DbSqlWriter writer = new DbSqlWriter();

            writer.Init(debug);
            DbIOMobSkills.Writer(debug, db);

            if (debug.DestinationServer == ServerType.RAthena)
            {
                writer.AppendHeader(ResourceString.Get("RAthenaMobSkillDbSqlHeader"));
            }
            else if (debug.DestinationServer == ServerType.Hercules)
            {
                writer.AppendHeader(ResourceString.Get("HerculesMobSkillDbSqlHeader"), writer.TableName.Replace("_re", ""));
                writer.TableName = "mob_skill_db";
            }

            foreach (string line in writer.Read())
            {
                string[] elements = TextFileHelper.ExcludeBrackets(line.Trim('\t'));
                if (!_getMobSkill(writer.IsHercules, writer.TableName, writer.Builder, elements))
                {
                    writer.Line(writer.IsHercules ? line.ReplaceFirst("//", "-- ") : line.ReplaceFirst("//", "#"));
                }
            }

            writer.Write();
        }
Beispiel #14
0
        public static void Writer(DbDebugItem <int> debug, AbstractDb <int> db)
        {
            try {
                if (db.Table.Commands.CommandIndex == -1 &&
                    !db.IsModified)
                {
                    return;
                }

                db.ProjectDatabase.MetaGrf.Clear();
                string path = ProjectConfiguration.ClientQuest;

                _dbClientQuestWrite(db.ProjectDatabase, db, path);

                try {
                    db.ProjectDatabase.MetaGrf.SaveAndReload();
                }
                catch (OperationCanceledException) {
                    ErrorHandler.HandleException("Failed to save the client files.");
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Beispiel #15
0
        public static void DbSqlItems(DbDebugItem <int> debug, AbstractDb <int> db)
        {
            DbSqlWriter writer = new DbSqlWriter();

            writer.Init(debug);

            if (debug.DestinationServer == ServerType.RAthena)
            {
                DbIOItems.DbItemsWriter(debug, db);
                writer.AppendHeader(ResourceString.Get(writer.IsRenewal ? "RAthenaItemDbSqlHeaderRenewal" : "RAthenaItemDbSqlHeader"));

                foreach (string line in writer.Read())
                {
                    string[] elements = TextFileHelper.ExcludeBrackets(line.Trim('\t'));
                    if (!_getItems(writer.IsRenewal, writer.TableName, writer.Builder, elements))
                    {
                        writer.Line(line.ReplaceFirst("//", "#"));
                    }
                }
            }
            else
            {
                var table = db.Table;
                writer.AppendHeader(ResourceString.Get("HerculesItemDbSqlHeader"), writer.TableName.Replace("_re", ""));

                foreach (var tuple in table.FastItems.OrderBy(p => p.GetKey <int>()))
                {
                    _getItemsHercules(writer.TableName, writer.Builder, tuple);
                }
            }

            writer.Write();
        }
Beispiel #16
0
        public static void DbSqlMobs <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            DbSqlWriter writer = new DbSqlWriter();

            writer.Init(debug);
            DbWriterMethods.DbIntComma(debug, db);

            if (debug.DestinationServer == ServerType.RAthena)
            {
                writer.AppendHeader(RAthenaMobDbSqlHeader);
            }
            else if (debug.DestinationServer == ServerType.Hercules)
            {
                writer.AppendHeader(HerculesMobDbSqlHeader, writer.TableName.Replace("_re", ""));
                writer.TableName = "mob_db";
            }

            foreach (string line in writer.Read())
            {
                string[] elements = TextFileHelper.ExcludeBrackets(line.Trim('\t'));
                if (!_getMob(writer.IsHercules, writer.TableName, writer.Builder, elements))
                {
                    writer.Line(writer.IsHercules ? line.ReplaceFirst("//", "--" + (writer.NumberOfLinesProcessed > 1 ? " " : "")) : line.ReplaceFirst("//", "#"));
                }
                else
                {
                    writer.NumberOfLinesProcessed++;
                }
            }

            writer.Write();
        }
        public static void DbItemsCommaWriter <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                StringBuilder builder = new StringBuilder();

                if (debug.FileType == FileType.Txt)
                {
                    if (AllLoaders.GetServerType() == ServerType.RAthena)
                    {
                        DbIntCommaRange(debug, db, 0, ServerItemAttributes.OnUnequipScript.Index + 1);
                        return;
                    }

                    DbItemsWriterSub(builder, db, db.Table.FastItems.OrderBy(p => p.GetKey <TKey>()), ServerType.RAthena);
                    File.WriteAllText(debug.FilePath, builder.ToString(), Encoding.Default);
                }
                else if (debug.FileType == FileType.Conf)
                {
                    builder.AppendLineUnix("item_db: (");
                    builder.Append(SqlParser.HerculesItemsDbTxtHeader);
                    DbItemsWriterSub(builder, db, db.Table.FastItems, ServerType.Hercules);
                    builder.AppendLineUnix(")");
                    File.WriteAllText(debug.FilePath, builder.ToString(), Encoding.Default);
                }
                else if (debug.FileType == FileType.Sql)
                {
                    SqlParser.DbSqlItems(debug, db);
                }
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Beispiel #18
0
        public static void Writer(DbDebugItem <int> debug, AbstractDb <int> db)
        {
            if (debug.FileType == FileType.Txt)
            {
                DbIOMethods.DbWriterComma(debug, db);
            }
            else if (debug.FileType == FileType.Yaml)
            {
                try {
                    var lines = new YamlParser(debug.OldPath, ParserMode.Write, "Id");

                    if (lines.Output == null)
                    {
                        return;
                    }

                    lines.Remove(db);

                    foreach (ReadableTuple <int> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <int>()))
                    {
                        string key = tuple.Key.ToString(CultureInfo.InvariantCulture);

                        StringBuilder builder = new StringBuilder();
                        WriteEntryYaml(builder, tuple);
                        lines.Write(key, builder.ToString().Trim('\r', '\n'));
                    }

                    lines.WriteFile(debug.FilePath);
                }
                catch (Exception err) {
                    debug.ReportException(err);
                }
            }
        }
Beispiel #19
0
        public static void DbSkillsCastCommaRange <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, int from, int length)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    List <string> items = tuple.GetRawElements().Skip(from).Take(length).Select(p => p.ToString()).ToList();

                    if (items.All(p => p == "0"))
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = string.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture) }.Concat(items).ToArray());
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Beispiel #20
0
        public static void Loader(DbDebugItem <int> debug, AbstractDb <int> db)
        {
            if (debug.FileType == FileType.Yaml)
            {
                var ele   = new YamlParser(debug.FilePath);
                var table = debug.AbsractDb.Table;

                if (ele.Output == null || ((ParserArray)ele.Output).Objects.Count == 0 || (ele.Output["copy_paste"] ?? ele.Output["Body"]) == null)
                {
                    return;
                }

                foreach (var castle in ele.Output["copy_paste"] ?? ele.Output["Body"])
                {
                    int castleId = (int)(object)Int32.Parse(castle["Id"]);

                    table.SetRaw(castleId, ServerCastleAttributes.MapName, castle["Map"] ?? "");
                    table.SetRaw(castleId, ServerCastleAttributes.CastleName, castle["Name"] ?? "");
                    table.SetRaw(castleId, ServerCastleAttributes.NpcName, castle["Npc"] ?? "");
                }
            }
            else if (debug.FileType == FileType.Txt)
            {
                DbIOMethods.DbLoaderComma(debug, db);
            }
        }
Beispiel #21
0
        public static void DbWriterComma(DbDebugItem <string> debug, AbstractDb <string> db)
        {
            try {
                StringLineStream lines = new StringLineStream(debug.OldPath, ',', false);
                lines.Remove(db);
                string line;

                int numOfElements = debug.AbsractDb.Table.AttributeList.Attributes.Count;
                var v             = debug.AbsractDb.Table.AttributeList.Attributes.FirstOrDefault(p => (p.Visibility & VisibleState.Hidden) == VisibleState.Hidden);

                if (v != null)
                {
                    numOfElements = debug.AbsractDb.Table.AttributeList.Attributes.IndexOf(v);
                }

                foreach (ReadableTuple <string> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.Key))
                {
                    line = string.Join(",", tuple.GetRawElements().Take(numOfElements).Select(p => (p ?? "").ToString()).ToArray());
                    lines.Write(tuple.Key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Beispiel #22
0
        public static void DbCommaRange <T>(DbDebugItem <T> debug, AttributeList list, int indexStart, int length, bool addAutomatically = true)
        {
            var table = debug.AbsractDb.Table;

            foreach (string[] elements in TextFileHelper.GetElementsByCommas(File.ReadAllBytes(debug.FilePath)))
            {
                try {
                    T itemId = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);

                    if (!addAutomatically && !table.ContainsKey(itemId))
                    {
                        Z.F();
                        continue;
                    }

                    int max = length;

                    for (int index = 1; index < elements.Length && max > 0; index++)
                    {
                        DbAttribute property = list.Attributes[index + indexStart - 1];
                        table.SetRaw(itemId, property, elements[index]);
                        max--;
                    }
                }
                catch (Exception err) {
                    if (!debug.ReportException(err))
                    {
                        return;
                    }
                }
            }
        }
Beispiel #23
0
        public static void DbItemsBuyingStore <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                TkDictionary <TKey, string[]> phantom = _getPhantomTable(debug);

                if (phantom != null)
                {
                    var itemDb = debug.AbsractDb.GetDb <TKey>(ServerDbs.Items).Table;

                    // Check if the phantom values differ from the Items1
                    foreach (var tuple in phantom)
                    {
                        if (debug.AbsractDb.Table.ContainsKey(tuple.Key))
                        {
                            continue;
                        }

                        var key    = tuple.Key;
                        var tuple1 = itemDb.TryGetTuple(key);

                        if (tuple1 != null)
                        {
                            bool val1 = tuple1.GetValue <bool>(ServerItemAttributes.BuyingStore);

                            if (val1 != true)
                            {
                                lines.Delete(tuple1.GetKey <int>());
                            }
                        }
                    }
                }

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    bool item1 = tuple.GetValue <bool>(ServerItemAttributes.BuyingStore);

                    if (!item1)
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = key.ToString(CultureInfo.InvariantCulture) + "  // " + tuple.GetValue <string>(ServerItemAttributes.AegisName);
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
        public static void DbIntCommaRange <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, int from, int to)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                for (int i = from; i < to; i++)
                {
                    DbAttribute att = db.AttributeList.Attributes[i];

                    if (att.Visibility == VisibleState.Hidden)
                    {
                        to = i;
                        break;
                    }
                }

                List <DbAttribute> attributes = new List <DbAttribute>(db.AttributeList.Attributes.Skip(from).Take(to));
                attributes.Reverse();

                List <DbAttribute> attributesToRemove =
                    (from attribute in attributes where db.Attached[attribute.DisplayName] != null
                     let isLoaded = (bool)db.Attached[attribute.DisplayName]
                                    where !isLoaded
                                    select attribute).ToList();

                IEnumerable <ReadableTuple <TKey> > list;

                if (db.Attached["EntireRewrite"] != null && (bool)db.Attached["EntireRewrite"])
                {
                    list = db.Table.FastItems.Where(p => !p.Deleted).OrderBy(p => p.GetKey <TKey>());
                }
                else
                {
                    list = db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>());
                }

                foreach (ReadableTuple <TKey> tuple in list)
                {
                    int           key         = tuple.GetKey <int>();
                    List <object> rawElements = tuple.GetRawElements().Skip(from).Take(to).ToList();

                    foreach (var attribute in attributesToRemove)
                    {
                        rawElements.RemoveAt(attribute.Index - from);
                    }

                    line = string.Join(",", rawElements.Select(p => (p ?? "").ToString()).ToArray());
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Beispiel #25
0
        public static void DbItemsTradeFunction <T>(DbDebugItem <T> debug, AttributeList list, string[] elements, Table <T, ReadableTuple <T> > table)
        {
            T itemId = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);

            Trade trade = new Trade();

            trade.Set(elements[1], elements[2]);
            table.SetRaw(itemId, ServerItemAttributes.Trade, trade);
        }
Beispiel #26
0
        public static void Writer <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            if (debug.FileType == FileType.Conf)
            {
                try {
                    var lines = new LibconfigParser(debug.OldPath, LibconfigMode.Write);
                    lines.Remove(db);
                    string line;

                    foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                    {
                        int           key     = tuple.GetKey <int>();
                        StringBuilder builder = new StringBuilder();
                        WriteEntry(builder, tuple);
                        line = builder.ToString();
                        lines.Write(key.ToString(CultureInfo.InvariantCulture), line);
                    }

                    lines.WriteFile(debug.FilePath);
                }
                catch (Exception err) {
                    debug.ReportException(err);
                }
            }
            else
            {
                int format = db.GetAttacked <int>("rAthenaFormat");

                try {
                    IntLineStream lines = new IntLineStream(debug.OldPath);
                    lines.Remove(db);
                    string line;

                    foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                    {
                        int key = tuple.GetKey <int>();

                        if (format == 18)
                        {
                            line = string.Join(",", tuple.GetRawElements().Select(p => (p ?? "").ToString()).ToArray());
                        }
                        else
                        {
                            line = string.Join(",", tuple.GetRawElements().Take(ServerQuestsAttributes.MobId1.Index).Concat(new object[] { tuple.GetRawValue(ServerQuestsAttributes.QuestTitle.Index) }).Select(p => (p ?? "").ToString()).ToArray());
                        }

                        lines.Write(key, line);
                    }

                    lines.WriteFile(debug.FilePath);
                }
                catch (Exception err) {
                    debug.ReportException(err);
                }
            }
        }
Beispiel #27
0
 public static void DbWriterAnyComma <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
 {
     if (typeof(TKey) == typeof(int))
     {
         DbWriterComma((DbDebugItem <int>)(object) debug, (AbstractDb <int>)(object) db, 0, db.AttributeList.Attributes.Count, (t, p) => { });
     }
     else
     {
         DbWriterComma((DbDebugItem <string>)(object) debug, (AbstractDb <string>)(object) db);
     }
 }
Beispiel #28
0
        public bool Init <TKey>(DbDebugItem <TKey> debug, string[] elements)
        {
            Id = null;
            Quantities.Clear();

            List <string> lines = elements.ToList();            //.Split(new char[] { TextFileHelper.SplitCharacter }, StringSplitOptions.RemoveEmptyEntries).ToList();

            if (lines.Count > 0)
            {
                Id = lines[0];
            }

            for (int index = 1; index < lines.Count; index++)
            {
                string line      = lines[index];
                int    lineIndex = 0;

                while (lineIndex < line.Length)
                {
                    if (line[lineIndex] == '(')
                    {
                        int end = line.IndexOf(')', lineIndex + 1);

                        if (end < 0)
                        {
                            return(debug.ReportIdExceptionWithError("Couln't find the parenthesis end branch.", Id));
                        }

                        string actualVal = line.Substring(lineIndex + 1, end - lineIndex - 1);
                        _add(actualVal);
                        lineIndex = end;
                    }
                    else if (line[lineIndex] == ' ' || line[lineIndex] == ',')
                    {
                    }
                    else if (line[lineIndex] == '\"')
                    {
                        int end = line.IndexOf('\"', lineIndex + 1);

                        if (end < 0)
                        {
                            return(debug.ReportIdExceptionWithError("Couln't find the parenthesis end branch.", Id));
                        }

                        string actualVal = line.Substring(lineIndex + 1, end - lineIndex - 1);
                        _add(actualVal);
                        lineIndex = end;
                    }
                    lineIndex++;
                }
            }

            return(true);
        }
Beispiel #29
0
 public static void Writer(DbDebugItem <int> debug, AbstractDb <int> db)
 {
     if (debug.FileType == FileType.Conf)
     {
         DbIOMethods.DbIOWriter(debug, db, WriteEntry);
     }
     else if (debug.FileType == FileType.Yaml)
     {
         DbIOMethods.DbIOWriter(debug, db, WriteEntryYaml);
     }
 }
Beispiel #30
0
        public static void DbItemsNouseFunction <T>(DbDebugItem <T> debug, AttributeList list, string[] elements, Table <T, ReadableTuple <T> > table)
        {
            T itemId = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);

            NoUse nouse = new NoUse();

            nouse.Sitting  = elements[1] == "1" ? "true" : "false";
            nouse.Override = elements[2];

            table.SetRaw(itemId, ServerItemAttributes.NoUse, nouse);
        }