Exemplo n.º 1
0
        private void SetPatchInfo(PatchContentType contentType, string text)
        {
            Dispatcher.Invoke(() =>
            {
                switch (contentType)
                {
                case PatchContentType.Text:
                    LabelTexts.Content = text;
                    break;

                case PatchContentType.Image:
                    LabelMaps.Content = text;
                    break;

                case PatchContentType.Sound:
                    LabelSounds.Content = text;
                    break;

                case PatchContentType.Font:
                    LabelFonts.Content = text;
                    break;

                case PatchContentType.Loadscreen:
                    LabelLoadscreens.Content = text;
                    break;

                case PatchContentType.Video:
                    LabelVideos.Content = text;
                    break;
                }
            });
        }
Exemplo n.º 2
0
        public static void CreateDatabase(PatchContentType contentType, string dir, string name)
        {
            try
            {
                var di = DatabaseInfoStore[contentType];

                di.DatabaseName = $"{dir}\\{name}.db";

                SQLiteConnection.CreateFile($"{di.DatabaseName}");

                using (var mDbConnection = new SQLiteConnection($"Data Source={di.DatabaseName};Version=3;"))
                {
                    mDbConnection.Open();

                    var cmdText = string.Format(di.CreateString, di.DataTableName);
                    using (var command = new SQLiteCommand(cmdText, mDbConnection))
                    {
                        command.ExecuteNonQuery();
                    }

                    using (var command = new SQLiteCommand(CreateMetadataTableString, mDbConnection))
                    {
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Write(ex.Message);
            }
        }
Exemplo n.º 3
0
        public static void PutMetadata(PatchContentType contentType)
        {
            try
            {
                var di = DatabaseInfoStore[contentType];

                using (var mDbConnection = new SQLiteConnection($"Data Source={di.DatabaseName};Version=3;"))
                {
                    mDbConnection.Open();

                    var cmdText =
                        $"INSERT INTO `{DatabaseShared.PatchMetadataTable}` VALUES (@name, @descr, '', '', @version, '', @contentType);";

                    using (var cmd = new SQLiteCommand(cmdText, mDbConnection))
                    {
                        cmd.Parameters.AddWithValue("@name", di.PatchName);
                        cmd.Parameters.AddWithValue("@descr", di.PatchDescr);
                        cmd.Parameters.AddWithValue("@version", di.Version);
                        cmd.Parameters.AddWithValue("@contentType", di.ContentType);

                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Write(ex.Message);
            }
        }
Exemplo n.º 4
0
 public abstract byte[] Data(uint id, shared.DatFile dat, SQLiteConnection con, Subfile subfile,
                             PatchContentType contentType,
                             ref int errors);
Exemplo n.º 5
0
        public override byte[] Data(uint id, shared.DatFile dat, SQLiteConnection con, Subfile subfile,
                                    PatchContentType contentType,
                                    ref int errors)
        {
            if (!dat.SubfileInfo.ContainsKey(id))
            {
                ++errors;
                Logger.Write($"файл #{id} не существует в ресурсах игры, пропускаю.");
                return(null);
            }

            var blob = Database.GetBlob(con, id);

            if (blob == null)
            {
                ++errors;
                Logger.Write($"файл #{id} не удалось прочитать из патча, пропускаю.");
                return(null);
            }

            using (var ms = new MemoryStream())
            {
                using (var sw = new BinaryWriter(ms, Encoding.Unicode))
                {
                    if (!subfile.IsValid)
                    {
                        ++errors;
                        return(null);
                    }

                    switch (contentType)
                    {
                    case PatchContentType.Image:
                        for (var i = 0; i < 20; ++i)
                        {
                            sw.Write(subfile.Data[i]);
                        }

                        sw.Write(blob.Length);
                        break;

                    case PatchContentType.Sound:
                        for (var i = 0; i < 4; ++i)
                        {
                            sw.Write(subfile.Data[i]);
                        }

                        sw.Write(blob.Length - 8);
                        break;

                    case PatchContentType.Texture:
                        // TODO - in case of modified width/height
                        for (var i = 0; i < 24; ++i)
                        {
                            sw.Write(subfile.Data[i]);
                        }

                        blob = blob.Skip(128).ToArray();
                        break;
                    }

                    sw.Write(blob);
                }

                return(ms.ToArray());
            }
        }
Exemplo n.º 6
0
 public DatPatchInfo(PatchContentType contentType)
 {
     ContentType = contentType;
 }
Exemplo n.º 7
0
 public PatchAppliedEventArgs(PatchContentType contentType, int errors)
 {
     Errors      = errors;
     ContentType = contentType;
 }
Exemplo n.º 8
0
 public PatchProgressEventArgs(PatchContentType contentType, int current, int all)
 {
     All         = all;
     Current     = current;
     ContentType = contentType;
 }
Exemplo n.º 9
0
 protected void OnPatchApplied(PatchContentType contentType, int errors)
 {
     PatchApplied?.Invoke(this, new PatchAppliedEventArgs(contentType, errors));
 }
Exemplo n.º 10
0
 protected void OnPatchListProgressChanged(PatchContentType contentType, int current, int all)
 {
     PatchListProgressChanged?.Invoke(this, new PatchProgressEventArgs(contentType, current, all));
 }
Exemplo n.º 11
0
 public Patch(PatchContentType contentType)
 {
     ContentType  = contentType;
     PatchVersion = new PatchVersion("null_U1_v100");
 }
Exemplo n.º 12
0
        public override byte[] Data(uint id, shared.DatFile dat, SQLiteConnection con, Subfile subfile,
                                    PatchContentType contentType,
                                    ref int errors)
        {
            if (!dat.SubfileInfo.ContainsKey(id))
            {
                ++errors;
                Logger.Write($"файл #{id} не существует в ресурсах игры, пропускаю.");
                return(null);
            }

            var fragments = Database.GetContent(con, id);

            if (fragments.Count == 0)
            {
                ++errors;
                Logger.Write($"файл #{id} пуст, пропускаю.");
                return(null);
            }

            if (!subfile.IsValid)
            {
                ++errors;
                return(null);
            }

            var orig = new TextSubfile(subfile.Data);

            if (!orig.IsValid)
            {
                ++errors;
                Logger.Write($"ошибка чтения файла #{id}, пропускаю весь файл.");
                return(null);
            }

            var skippedFragmentsCount = fragments.Count(fragment => !orig.Body.ContainsKey(fragment.Key));

            if (skippedFragmentsCount == fragments.Count)
            {
                ++errors;
                Logger.Write($"ни один фрагмент не подходит для перезаписи файла #{id}, пропускаю весь файл.");
                return(null);
            }

            if (skippedFragmentsCount > 0)
            {
                Logger.Write($"{skippedFragmentsCount} неопознанных фрагментов в патче для файла #{id} будет пропущено.");
            }

            using (var ms = new MemoryStream())
            {
                using (var sw = new BinaryWriter(ms, Encoding.Unicode))
                {
                    //Logger.Write($"Кек #{orig.Head.Unknown}");
                    sw.Write(id);
                    sw.Write(orig.Head.Unknown);
                    //sw.Write(0);
                    sw.Write(orig.Head.Unknown2);
                    ByteOrShort(sw, orig.Head.Fragments);

                    var missingFragmentsCount = 0;
                    foreach (var body in orig.Body)
                    {
                        // detect possible errors
                        var useDefault = false;

                        // patch does not contain data for this fragment
                        if (!fragments.ContainsKey(body.Key))
                        {
                            missingFragmentsCount++;
                            useDefault = true;
                            Logger.Write($"файл #{id}, фрагмент #{body.Key} - отсутствует в патче, использую оригинал.");
                        }

                        // patch fragment args contain error
                        if (!useDefault && fragments[body.Key].IsArgsError)
                        {
                            missingFragmentsCount++;
                            useDefault = true;
                            Logger.Write($"файл #{id}, фрагмент #{body.Key} - ошибка в строке аргументов, использую оригинал.");
                        }

                        // patch fragment args order contains error
                        if (!useDefault && fragments[body.Key].IsOrderError)
                        {
                            missingFragmentsCount++;
                            useDefault = true;
                            Logger.Write($"файл #{id}, фрагмент #{body.Key} - ошибка в строке порядка, использую оригинал.");
                        }

                        // patch fragment text contain error
                        if (!useDefault && !fragments[body.Key].IsValid)
                        {
                            missingFragmentsCount++;
                            useDefault = true;
                            Logger.Write($"файл #{id}, фрагмент #{body.Key} - ошибка в содержимом, использую оригинал.");
                        }

                        var pieces = useDefault
                            ? body.Value.Pieces
                            : fragments[body.Key].Content.Split(new[] { "<--DO_NOT_TOUCH!-->" }, StringSplitOptions.None);

                        // patch args order was intentionally emptied, force it
                        if (!useDefault && fragments[body.Key].ArgsOrder.Length == 0 && fragments[body.Key].Args.Length > 0 && pieces.Length == 1)
                        {
                            fragments[body.Key].IsDefaultOrder = false;
                        }

                        // broken relation between args count and their plant holes
                        if (!useDefault &&
                            (!fragments[body.Key].IsDefaultOrder &&
                             fragments[body.Key].ArgsOrder.Length != pieces.Length - 1 ||
                             fragments[body.Key].IsDefaultOrder &&
                             fragments[body.Key].Args.Length != pieces.Length - 1))
                        {
                            missingFragmentsCount++;
                            useDefault = true;
                            pieces     = body.Value.Pieces;
                            Logger.Write($"файл #{id}, фрагмент #{body.Key} - ошибка в строке порядка, использую оригинал.");
                        }

                        // write token
                        sw.Write(body.Key);

                        // write pieces
                        sw.Write(pieces.Length);

                        foreach (var piece in pieces)
                        {
                            var length = (short)piece.Length;
                            ByteOrShort(sw, length);
                            sw.Write(Encoding.Unicode.GetBytes(piece));
                        }

                        if (useDefault)
                        {
                            var args = body.Value.Arguments;
                            sw.Write(args.Length);

                            foreach (var arg in args)
                            {
                                sw.Write(arg);
                            }
                        }
                        else
                        {
                            if (fragments[body.Key].IsDefaultOrder)
                            {
                                // use patch default args (ignore patch args order or empty patch args order)
                                var args = fragments[body.Key].Args;
                                sw.Write(args.Length);

                                foreach (var arg in args)
                                {
                                    sw.Write(arg);
                                }
                            }
                            else
                            {
                                #if DEBUG
                                if (fragments[body.Key].IsExtraOrder)
                                {
                                    Logger.Write($"фрагмент #{body.Key} из файла #{id} - порядок аргументов длиннее исходного.");
                                }
                                #endif

                                // use patch alt args order
                                sw.Write(fragments[body.Key].ArgsOrder.Length);

                                foreach (var ord in fragments[body.Key].ArgsOrder)
                                {
                                    sw.Write(fragments[body.Key].Args[ord - 1]);
                                }
                            }
                        }

                        // use original variables
                        var vars = body.Value.Variables;
                        sw.Write((byte)vars.Length);
                        foreach (var pack in vars)
                        {
                            sw.Write(pack.Length);
                            foreach (var rice in pack)
                            {
                                var length = (short)rice.Length;
                                ByteOrShort(sw, length);
                                sw.Write(Encoding.Unicode.GetBytes(rice));
                            }
                        }
                    }

                    if (missingFragmentsCount > 0)
                    {
                        Logger.Write(
                            $"{missingFragmentsCount} из {orig.Head.Fragments} фрагментов в файле #{id} не изменились.");
                    }
                }

                return(ms.ToArray());
            }
        }