Пример #1
0
        public static void WeaponViewIdRepair(SdeDatabase sdb, BaseDb currentDb)
        {
            var itemDb  = sdb.GetMetaTable <int>(ServerDbs.Items);
            var itemDb1 = sdb.GetDb <int>(ServerDbs.Items);
            var itemDb2 = sdb.GetDb <int>(ServerDbs.Items2);

            string error;
            Dictionary <int, string> dico;

            if (LuaHelper.GetIdToSpriteTable(itemDb2, LuaHelper.ViewIdTypes.Weapon, out dico, out error))
            {
            }

            foreach (var tuple in itemDb1.Table.FastItems)
            {
                if (ItemParser.IsWeaponType(tuple))
                {
                    int viewId = tuple.GetIntNoThrow(ServerItemAttributes.ClassNumber);
                }
            }
        }
Пример #2
0
        private static void _dbClientQuestWrite(SdeDatabase gdb, AbstractDb <int> db, string path)
        {
            if (path == null || gdb.MetaGrf.GetData(path) == null)
            {
                Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CQuests, "data\\questid2display.txt", null, "Table not saved."));
                return;
            }

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

            //string tmpFilename = Path.Combine(SdeAppConfiguration.TempPath, Path.GetFileName(path));
            Encoding encoder = EncodingService.DisplayEncoding;

            byte[] tmpBuffer;
            byte[] lineFeedByte       = encoder.GetBytes(SdeStrings.LineFeed);
            byte[] doubleLineFeedByte = encoder.GetBytes(SdeStrings.LineFeed + SdeStrings.LineFeed);

            using (MemoryStream memStream = new MemoryStream()) {
                IEnumerable <ReadableTuple <int> > items = gdb.GetDb <int>(ServerDbs.CQuests).Table.GetSortedItems();

                foreach (ReadableTuple <int> item in items)
                {
                    tmpBuffer = encoder.GetBytes(
                        item.GetValue <int>(ClientQuestsAttributes.Id) + "#" +
                        item.GetValue <string>(ClientQuestsAttributes.Name) + "#" +
                        item.GetValue <string>(ClientQuestsAttributes.SG) + "#" +
                        item.GetValue <string>(ClientQuestsAttributes.QUE) + "#" +
                        "\r\n" + item.GetValue <string>(ClientQuestsAttributes.FullDesc) + "#" +
                        "\r\n" + item.GetValue <string>(ClientQuestsAttributes.ShortDesc) + "#");

                    memStream.Write(tmpBuffer, 0, tmpBuffer.Length);
                    memStream.Write(doubleLineFeedByte, 0, doubleLineFeedByte.Length);
                }

                memStream.Write(lineFeedByte, 0, lineFeedByte.Length);

                tmpBuffer = new byte[memStream.Length];
                Buffer.BlockCopy(memStream.GetBuffer(), 0, tmpBuffer, 0, tmpBuffer.Length);

                //File.WriteAllBytes(tmpFilename, tmpBuffer);
            }

            string copyPath = path;

            try {
                gdb.MetaGrf.SetData(copyPath, tmpBuffer);
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }

            Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CQuests, db.ProjectDatabase.MetaGrf.FindTkPath(path), null, "Saving client table (questdb)."));
        }
Пример #3
0
        private static void _saveItemDataToLua(SdeDatabase gdb, string filename, string output)
        {
            if (output == null && gdb.MetaGrf.GetData(filename) == null)
            {
                Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CItems, filename, null, "ItemInfo table not saved."));
                return;
            }

            if (output == null)
            {
                BackupEngine.Instance.BackupClient(filename, gdb.MetaGrf);
            }

            StringBuilder builder = new StringBuilder();

            builder.AppendLine("tbl = {");

            List <ReadableTuple <int> > tuples = gdb.GetDb <int>(ServerDbs.CItems).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("ItemInfoFunction"));

            if (output == null)
            {
                gdb.MetaGrf.SetData(filename, EncodingService.Ansi.GetBytes(builder.ToString()));
            }
            else
            {
                string copyPath = Path.Combine(output, Path.GetFileName(filename));

                try {
                    File.WriteAllText(copyPath, builder.ToString(), EncodingService.Ansi);
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            }

            Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CItems, gdb.MetaGrf.FindTkPath(filename), null, "Saving ItemInfo table."));
        }
Пример #4
0
 public static string GetSpriteFromViewId(int viewIdToFind, ViewIdTypes type, SdeDatabase db, ReadableTuple <int> tuple)
 {
     return(GetSpriteFromViewId(viewIdToFind, type, db.GetDb <int>(ServerDbs.Items), tuple));
 }
Пример #5
0
        private static void _saveFile(SdeDatabase gdb, string filename, string output, DbAttribute attribute, RequiredCondition <ReadableTuple <int> > condition = null, bool allowReturns = true)
        {
            if (output == null && gdb.MetaGrf.GetData(filename) == null)
            {
                Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CItems, filename, null, "Table not saved (" + attribute.GetQueryName() + ")."));
                return;
            }

            if (output == null)
            {
                BackupEngine.Instance.BackupClient(filename, gdb.MetaGrf);
            }

            string   tmpFilename = Path.Combine(SdeAppConfiguration.TempPath, Path.GetFileName(filename));
            Encoding encoder     = EncodingService.DisplayEncoding;

            byte[] tmpBuffer;
            byte[] lineFeedByte       = encoder.GetBytes(SdeStrings.LineFeed);
            byte[] doubleLineFeedByte = encoder.GetBytes(SdeStrings.LineFeed + SdeStrings.LineFeed);

            using (MemoryStream memStream = new MemoryStream()) {
                IEnumerable <ReadableTuple <int> > items = gdb.GetDb <int>(ServerDbs.CItems).Table.GetSortedItems();

                int  previousId = -1;
                bool firstItem  = true;

                foreach (ReadableTuple <int> item in items)
                {
                    if (condition == null || condition(item))
                    {
                        string itemProperty = attribute != null?item.GetRawValue(attribute.Index) as string : null;

                        if (itemProperty != null || attribute == null)
                        {
                            if (attribute == ClientItemAttributes.IdentifiedDisplayName || attribute == ClientItemAttributes.UnidentifiedDisplayName)
                            {
                                itemProperty = itemProperty.Replace(" ", "_");
                            }

                            if (!firstItem)
                            {
                                if (allowReturns)
                                {
                                    if (previousId == (item.GetValue <int>(ClientItemAttributes.Id) - 1))
                                    {
                                        memStream.Write(lineFeedByte, 0, lineFeedByte.Length);
                                    }
                                    else
                                    {
                                        memStream.Write(doubleLineFeedByte, 0, doubleLineFeedByte.Length);
                                    }
                                }
                                else
                                {
                                    memStream.Write(lineFeedByte, 0, lineFeedByte.Length);
                                }
                            }

                            if (attribute == null)
                            {
                                tmpBuffer = encoder.GetBytes(item.GetValue <int>(ClientItemAttributes.Id) + "#");
                            }
                            else
                            {
                                tmpBuffer = encoder.GetBytes(item.GetValue <int>(ClientItemAttributes.Id) + "#" + itemProperty + "#");
                            }

                            memStream.Write(tmpBuffer, 0, tmpBuffer.Length);

                            previousId = item.GetValue <int>(ClientItemAttributes.Id);
                            firstItem  = false;
                        }
                    }
                }

                memStream.Write(lineFeedByte, 0, lineFeedByte.Length);

                tmpBuffer = new byte[memStream.Length];
                Buffer.BlockCopy(memStream.GetBuffer(), 0, tmpBuffer, 0, tmpBuffer.Length);

                File.WriteAllBytes(tmpFilename, tmpBuffer);
            }

            if (output == null)
            {
                var data    = gdb.MetaGrf.GetData(filename);
                var toWrite = File.ReadAllBytes(tmpFilename);

                if (data != null && Methods.ByteArrayCompare(data, toWrite))
                {
                    return;
                }

                gdb.MetaGrf.SetData(filename, toWrite);
            }
            else
            {
                string copyPath = Path.Combine(output, Path.GetFileName(filename));

                try {
                    File.Delete(copyPath);
                    File.Copy(tmpFilename, copyPath);
                    File.Delete(tmpFilename);
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            }

            Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CItems, gdb.MetaGrf.FindTkPath(filename), null, "Saving client table (" + (attribute == null ? "" : attribute.GetQueryName()) + ")."));
        }
Пример #6
0
        private void _autoAdd(bool full)
        {
            try {
                var itemDb  = _gdb.GetMetaTable <int>(ServerDbs.Items);
                var citemDb = _gdb.GetDb <int>(ServerDbs.CItems);

                List <ReadableTuple <int> > headgears = itemDb.FastItems.Where(p => ItemParser.IsArmorType(p) && (p.GetIntNoThrow(ServerItemAttributes.Location) & 7937) != 0).OrderBy(p => p.GetIntNoThrow(ServerItemAttributes.ClassNumber)).ToList();

                foreach (var sTuple in headgears)
                {
                    var viewId = sTuple.GetIntNoThrow(ServerItemAttributes.ClassNumber);

                    if (viewId == 0)
                    {
                        continue;
                    }

                    var cTuple  = citemDb.Table.TryGetTuple(sTuple.Key);
                    var item    = _obItems.FirstOrDefault(p => p.Id == viewId);
                    var accName = LuaHelper.LatinOnly(sTuple.GetValue <string>(ServerItemAttributes.AegisName));

                    if (cTuple == null)
                    {
                        if (item == null)
                        {
                            _obItems.Add(new AccessoryItemView(new AccessoryItem {
                                Id = viewId, AccId = full ? "ACCESSORY_" + accName : null, Texture = ""
                            }));
                        }
                        else
                        {
                            if (String.IsNullOrEmpty(item.Texture) && full)
                            {
                                item.Texture = accName;
                            }

                            if (String.IsNullOrEmpty(item.AccId) && full)
                            {
                                item.AccId = "ACCESSORY_" + accName;
                            }
                        }
                        continue;
                    }


                    if (item == null)
                    {
                        _obItems.Add(new AccessoryItemView(new AccessoryItem {
                            Id = viewId, AccId = full ? "ACCESSORY_" + accName : null, Texture = cTuple.GetValue <string>(ClientItemAttributes.IdentifiedResourceName)
                        }));
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(item.Texture))
                        {
                            item.Texture = cTuple.GetValue <string>(ClientItemAttributes.IdentifiedResourceName);
                        }

                        if (String.IsNullOrEmpty(item.AccId) && full)
                        {
                            item.AccId = "ACCESSORY_" + accName;
                        }
                    }
                }

                if (_obItems.Count > 0)
                {
                    _dataGrid.ScrollIntoView(_obItems.Last());
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }