Пример #1
0
        public PointerText GetOriginalPointerInfo(Int32 textPointer)
        {
            var result = new PointerText();

            result.Address    = textPointer;
            result.References = FindTextReferences(textPointer);

            bool endFound           = false;
            int  overFlowProtection = 1000; //Max string length of 1000 to prevent an overflow into binary data.
            int  index     = textPointer;
            var  textBytes = new List <Byte>();

            while (!endFound && overFlowProtection-- > 0 && index < RomContents.Length)
            {
                var value = RomContents[index];
                if (value == end)
                {
                    result.AvailableLength = textBytes.Count;
                    endFound = true;
                }
                else
                {
                    textBytes.Add(value);
                }
                index++;
            }
            result.AvailableLength        = textBytes.Count;
            result.UntranslatedSingleLine = TextHandler.TranslateBinaryToString(textBytes);
            return(result);
        }
Пример #2
0
        private static List <Int32> LoadTranslationBaseLines(String translationFileName)
        {
            var translationSourceFile = new FileInfo(translationFileName);

            if (!translationSourceFile.Exists)
            {
                Console.WriteLine("Translation source file {0} does not exist", translationFileName);
                return(null);
            }
            return(PointerText.ReadPointersFromFile(translationSourceFile).Select(l => l.Address).ToList());
        }
Пример #3
0
        private static List <PointerText> LoadTranslationFileLines(String translationFileName)
        {
            var translationSourceFile = new FileInfo(translationFileName);

            if (!translationSourceFile.Exists)
            {
                log.FatalFormat("Translation source file {0} does not exist", translationFileName);
                Console.WriteLine("Translation source file {0} does not exist", translationFileName);
                return(null);
            }
            return(PointerText.ReadPointersFromFile(translationSourceFile));
        }
Пример #4
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);
        }
Пример #5
0
        public static List <PointerText> ReadPointersFromFile(FileInfo file)
        {
            var lines = new List <PointerText>();

            using (var sourceReader = new StreamReader(file.OpenRead(), Encoding.GetEncoding(1252)))
            {
                var sourceLine = sourceReader.ReadLine();
                while (sourceLine != null)
                {
                    if (sourceLine.Length > 5 && PointerText.HexChars.Contains(sourceLine[0]))
                    {
                        lines.Add(PointerText.FromString(sourceLine));
                    }
                    sourceLine = sourceReader.ReadLine();
                }
            }
            return(lines);
        }
Пример #6
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();
        }