示例#1
0
        static bool BenchmarkFile(byte[] compressedBuffer, uint offset, out float compressionRatio)
        {
            compressionRatio = 0f;

            Console.ForegroundColor = ConsoleColor.Gray;
            Console.Write($"Processing data at 0x{offset:X8}... ");

            byte[] uncompressedBuffer;

            try
            {
                uncompressedBuffer = MPCompression.Decompress(compressedBuffer);
            }
            catch (InvalidDataException ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
                return(false);
            }

            byte[] compressedBuffer2   = MPCompression.Compress(uncompressedBuffer);
            byte[] uncompressedBuffer2 = MPCompression.Decompress(compressedBuffer2);

            bool areEqual = Utils.CompareArrays(uncompressedBuffer, uncompressedBuffer2);

            if (!areEqual)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Decompression mismatch.");
                return(false);
            }

            compressionRatio = (float)compressedBuffer2.Length / compressedBuffer.Length;

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"Done! Compression ratio: {compressionRatio}");

            return(true);
        }
示例#2
0
        static void Main(string[] args)
        {
            ShowHeader();

            try
            {
                if (args.Length == 2)
                {
                    if (args[0] == "-b")
                    {
                        ROM.Benchmark(args[1]);
                    }
                    else
                    {
                        ShowUsage();
                    }
                }
                else if (args.Length == 3)
                {
                    if (args[0] == "-d")
                    {
                        MPCompression.Decompress(args[1], args[2]);

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Decompression process finished successfully.\n");
                    }
                    else if (args[0] == "-c")
                    {
                        MPCompression.Compress(args[1], args[2]);

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Compression process finished successfully.\n");
                    }
                    else if (args[0] == "-me")
                    {
                        ROM.MassExtraction(args[1], args[2], false);

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Mass extraction process finished successfully.\n");
                    }
                    else if (args[0] == "-md")
                    {
                        ROM.MassExtraction(args[1], args[2], true);

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Mass decompression process finished successfully.\n");
                    }
                    else
                    {
                        ShowUsage();
                    }
                }
                else if (args.Length == 4)
                {
                    if (args[0] == "-et")
                    {
                        Table table = new Table(args[3]);
                        Texts.Extract(args[1], args[2], table);

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Extracted all texts successfully.\n");
                    }
                    else if (args[0] == "-it")
                    {
                        Table table = new Table(args[3]);
                        Texts.Insert(args[1], args[2], table);

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Inserted all texts successfully.\n");
                    }
                    else
                    {
                        ShowUsage();
                    }
                }
                else
                {
                    ShowUsage();
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
            }

            Console.ForegroundColor = ConsoleColor.Gray;

#if DEBUG
            Console.ReadLine();
#endif
        }