Esempio n. 1
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                throw new ArgumentException("Pass a rom file, advance text ini to parse and output file.");
            }

            var outputFile = new FileInfo(args[2]);

            if (outputFile.Exists)
            {
                throw new Exception("Output file already exists. Please specify another name.");
            }

            var foundText = new Dictionary <Int32, PointerText>();

            var rom = new RomDataWrapper(new FileInfo(args[0]));

            var    bpre = new FileInfo(args[1]);
            String bpreContents;

            using (var reader = bpre.OpenText())
            {
                bpreContents = reader.ReadToEnd();
            }

            var expr        = new Regex("[0-9A-F]{6}");
            var exprMatches = expr.Matches(bpreContents);
            var sw          = new Stopwatch();

            sw.Start();
            foreach (Match match in exprMatches)
            {
                if (Int32.TryParse(match.Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int intValue))
                {
                    if (foundText.ContainsKey(intValue))
                    {
                        Console.WriteLine("Pointer {0:X6} appears multiple times in BPRE, will be skipped.", intValue);
                    }
                    else
                    {
                        var text = rom.GetOriginalPointerInfo(intValue);
                        text.Group = FindGroup(bpreContents, match.Index);
                        foundText.Add(intValue, text);
                    }
                }
            }

            PointerText.WritePointersToFile(outputFile, foundText.Values);
            sw.Stop();

            Console.WriteLine("On {0} searches searching took {1}", exprMatches.Count, sw.Elapsed);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                throw new ArgumentException("Pass a rom file, an existing translation file and an output file.");
            }
            var rom = new RomDataWrapper(new FileInfo(args[0]));

            var tmpRomData = new Byte[rom.RomContents.Length - (skipBlockEnd - skipBlockStart)];

            Array.Copy(rom.RomContents, tmpRomData, skipBlockStart);
            Array.Copy(rom.RomContents, skipBlockEnd, tmpRomData, skipBlockStart, rom.RomContents.Length - skipBlockEnd);

            var romWithHole = new RomDataWrapper(tmpRomData);

            existingtranslationLines = LoadTranslationBaseLines(args[1]);
            if (existingtranslationLines == null)
            {
                existingtranslationLines = new List <Int32>();
            }
            for (int i = 0; i < existingtranslationLines.Count; i++)
            {
                if (existingtranslationLines[i] > skipBlockEnd)
                {
                    existingtranslationLines[i] -= (skipBlockEnd - skipBlockStart);
                }
            }

            var outputFile = new FileInfo(args[2]);

            if (outputFile.Exists)
            {
                throw new Exception(String.Format("The output file {0} already exists.", args[2]));
            }

            var sw = new Stopwatch();

            sw.Start();

            var numThreads   = Environment.ProcessorCount;
            var numPerThread = (romWithHole.RomContents.Length - startPosition) / numThreads;
            var tasks        = new List <Task>();

            for (int i = 0; i < numThreads - 1; i++)
            {
                var name = "FT" + (i + 1);
                var from = startPosition + numPerThread * i;
                var to   = startPosition + numPerThread * (i + 1);
                tasks.Add(Task.Run(() => FindStringPointers(name, romWithHole, from, to)));
            }
            tasks.Add(Task.Run(() => FindStringPointers("FT" + numThreads, romWithHole, startPosition + numPerThread * (numThreads - 1), romWithHole.RomContents.Length)));
            Task.WaitAll(tasks.ToArray());

            sw.Stop();

            Console.WriteLine("Finding text in {0} bytes took {1}", romWithHole.RomContents.Length, sw.Elapsed);

            for (int i = 0; i < newTranslationLines.Count; i++)
            {
                if (newTranslationLines[i] > skipBlockStart)
                {
                    newTranslationLines[i] += (skipBlockEnd - skipBlockStart);
                }
            }

            var linesToTranslate = LoadNewTranslationLines(rom);

            Console.Write("\rReading progress: 100%   ");
            Console.WriteLine();

            Console.WriteLine("Writing missed text entries to file.");

            PointerText.WritePointersToFile(outputFile, linesToTranslate.OrderBy(l => l.Address));

            Console.WriteLine("Done, press any key to continue...");
            Console.ReadLine();
        }