Esempio n. 1
0
        private static void _loadDataQuest(AbstractDb <int> db, string file)
        {
            var table = db.Table;

            TextFileHelper.LatestFile = file;

            try {
                foreach (string[] elements in TextFileHelper.GetElementsInt(db.ProjectDatabase.MetaGrf.GetData(file)))
                {
                    int itemId = Int32.Parse(elements[0]);

                    table.SetRaw(itemId, ClientQuestsAttributes.Name, elements[1]);
                    table.SetRaw(itemId, ClientQuestsAttributes.SG, elements[2]);
                    table.SetRaw(itemId, ClientQuestsAttributes.QUE, elements[3]);
                    table.SetRaw(itemId, ClientQuestsAttributes.FullDesc, elements[4]);
                    table.SetRaw(itemId, ClientQuestsAttributes.ShortDesc, elements[5]);
                }

                Debug.Ignore(() => DbDebugHelper.OnLoaded(db.DbSource, db.ProjectDatabase.MetaGrf.FindTkPath(file), db));
            }
            catch (Exception err) {
                Debug.Ignore(() => DbDebugHelper.OnExceptionThrown(db.DbSource, file, db));
                throw new Exception(TextFileHelper.GetLastError(), err);
            }
        }
Esempio n. 2
0
        private static void _loadData <T>(AbstractDb <T> db, string file, DbAttribute attribute, bool allowCutLine = true, bool removeUnderscore = false)
        {
            var table = db.Table;

            TextFileHelper.LatestFile = file;

            try {
                foreach (string[] elements in TextFileHelper.GetElements(db.ProjectDatabase.MetaGrf.GetData(file), allowCutLine))
                {
                    T itemId = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);
                    table.SetRaw(itemId, attribute, removeUnderscore ? elements[1].Replace("_", " ") : elements[1]);
                }

                Debug.Ignore(() => DbDebugHelper.OnLoaded(db.DbSource, db.ProjectDatabase.MetaGrf.FindTkPath(file), db));
            }
            catch (Exception err) {
                Debug.Ignore(() => DbDebugHelper.OnExceptionThrown(db.DbSource, file, db));
                throw new Exception(TextFileHelper.GetLastError(), err);
            }
        }
Esempio n. 3
0
        private static void _loadCardPostfixes(AbstractDb <int> db, byte[] data)
        {
            var table = db.Table;
            DbDebugItem <int> debug = new DbDebugItem <int>(null);

            TextFileHelper.LatestFile = db.ProjectDatabase.MetaGrf.LatestFile;

            foreach (string element in TextFileHelper.GetSingleElement(data))
            {
                try {
                    int itemId = Int32.Parse(element);
                    table.SetRaw(itemId, ClientItemAttributes.IsCard, true, true);
                    table.SetRaw(itemId, ClientItemAttributes.Postfix, true, true);
                }
                catch (Exception err) {
                    if (!debug.ReportException(err))
                    {
                        return;
                    }
                }
            }

            Debug.Ignore(() => DbDebugHelper.OnLoaded(db.DbSource, db.ProjectDatabase.MetaGrf.FindTkPath(db.ProjectDatabase.MetaGrf.LatestFile), db));
        }
Esempio n. 4
0
        public static void Loader(AbstractDb <int> db, string file)
        {
            if (file == null)
            {
                Debug.Ignore(() => DbDebugHelper.OnUpdate(db.DbSource, null, "achievement_list table will not be loaded."));
                return;
            }

            LuaList list;

            var table   = db.Table;
            var metaGrf = db.ProjectDatabase.MetaGrf;

            string outputPath = GrfPath.Combine(SdeAppConfiguration.TempPath, Path.GetFileName(file));

            byte[] itemData = metaGrf.GetData(file);

            if (itemData == null)
            {
                Debug.Ignore(() => DbDebugHelper.OnUpdate(db.DbSource, file, "File not found."));
                return;
            }

            File.WriteAllBytes(outputPath, itemData);

            if (!File.Exists(outputPath))
            {
                return;
            }

            if (Methods.ByteArrayCompare(itemData, 0, 4, new byte[] { 0x1b, 0x4c, 0x75, 0x61 }, 0))
            {
                // Decompile lub file
                Lub lub  = new Lub(itemData);
                var text = lub.Decompile();
                itemData = EncodingService.DisplayEncoding.GetBytes(text);
                File.WriteAllBytes(outputPath, itemData);
            }

            DbIOMethods.DetectAndSetEncoding(itemData);

            using (LuaReader reader = new LuaReader(outputPath, DbIOMethods.DetectedEncoding)) {
                list = reader.ReadAll();
            }

            LuaKeyValue itemVariable = list.Variables[0] as LuaKeyValue;

            if (itemVariable != null && itemVariable.Key == "achievement_tbl")
            {
                LuaList items = itemVariable.Value as LuaList;

                if (items != null)
                {
                    foreach (LuaKeyValue item in items.Variables)
                    {
                        _loadEntry(table, item);
                    }
                }
            }
            else
            {
                // Possible copy-paste data
                foreach (LuaKeyValue item in list.Variables)
                {
                    _loadEntry(table, item);
                }
            }

            Debug.Ignore(() => DbDebugHelper.OnLoaded(db.DbSource, metaGrf.FindTkPath(file), db));
        }
Esempio n. 5
0
        private void _menuItemUpdateClientQuests_Click(object sender, RoutedEventArgs e)
        {
            try {
                var tab = FindTopmostTab();

                if (tab == null)
                {
                    return;
                }

                string file = PathRequest.OpenFileCde("fileName", "iRO-questid2display.txt");

                if (file != null)
                {
                    var db    = ProjectDatabase.GetDb <int>(ServerDbs.CQuests);
                    var table = db.Table;

                    try {
                        table.Commands.BeginNoDelay();

                        foreach (string[] elements in TextFileHelper.GetElementsInt(File.ReadAllBytes(file)))
                        {
                            int itemId = Int32.Parse(elements[0]);
                            var tuple  = table.TryGetTuple(itemId);

                            if (tuple != null)
                            {
                                DbIOClientQuests.SetQuestValue(table, tuple, elements, 1);
                                table.Set(itemId, ClientQuestsAttributes.SG, elements[2]);
                                table.Set(itemId, ClientQuestsAttributes.QUE, elements[3]);
                                DbIOClientQuests.SetQuestValue(table, tuple, elements, 4);
                                DbIOClientQuests.SetQuestValue(table, tuple, elements, 5);
                            }
                            else
                            {
                                ReadableTuple <int> newTuple = new ReadableTuple <int>(itemId, ClientQuestsAttributes.AttributeList);
                                table.Commands.AddTuple(itemId, newTuple);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.Name, elements[1]);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.SG, elements[2]);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.QUE, elements[3]);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.FullDesc, elements[4]);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.ShortDesc, elements[5]);
                            }
                        }

                        var db2 = db.ProjectDatabase.GetMetaTable <int>(ServerDbs.Quests);

                        foreach (var quest in db2.FastItems)
                        {
                            var id    = quest.Key;
                            var tuple = table.TryGetTuple(id);

                            if (tuple != null)
                            {
                                DbIOClientQuests.SetQuestValue(table, tuple, quest.GetValue <string>(ServerQuestsAttributes.QuestTitle), ClientQuestsAttributes.Name.Index);
                            }
                            else
                            {
                                ReadableTuple <int> newTuple = new ReadableTuple <int>(id, ClientQuestsAttributes.AttributeList);
                                table.Commands.AddTuple(id, newTuple);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.Name, quest.GetValue <string>(ServerQuestsAttributes.QuestTitle));
                                table.Commands.Set(newTuple, ClientQuestsAttributes.SG, "SG_FEEL");
                                table.Commands.Set(newTuple, ClientQuestsAttributes.QUE, "QUE_NOIMAGE");
                                table.Commands.Set(newTuple, ClientQuestsAttributes.FullDesc, "...");
                                table.Commands.Set(newTuple, ClientQuestsAttributes.ShortDesc, "");
                            }
                        }

                        Debug.Ignore(() => DbDebugHelper.OnLoaded(db.DbSource, db.ProjectDatabase.MetaGrf.FindTkPath(file), db));
                    }
                    catch (Exception err) {
                        table.Commands.CancelEdit();
                        ErrorHandler.HandleException(err);
                    }
                    finally {
                        table.Commands.End();
                    }
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }