Esempio n. 1
0
        /// <summary>
        /// The new implementation of Rip.
        /// </summary>
        private static void NewRip(RipOptions options)
        {
            // Read emulated memory.
            var process = new ExternalMemory(Process.GetProcessesByName(options.ProcessName)[0]);

            // Parse known file list.
            var sizeToFileMap = JsonFile.FromFileAsSizeToFileMap(options.JsonPath);

            // Read PCSX2 Logs
            using var fileStream = new FileStream(options.LogPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            var logData = new byte[fileStream.Length];

            fileStream.Read(logData);

            // Get size, address from log.
            var pcsx2Log        = Encoding.UTF8.GetString(logData);
            var memoryDumpRegex = new Regex(@"^Addr: ([\d]*) , Size: ([\d]*), DumpFlagAddr: ([\d]*) [\n\r]+", RegexOptions.Multiline);
            var lastMatch       = memoryDumpRegex.Matches(pcsx2Log).Last();
            var archiveOffset   = Convert.ToInt32(lastMatch.Groups[1].Value);
            var fileSize        = Convert.ToInt32(lastMatch.Groups[2].Value);
            var dumpFlagAddr    = Convert.ToInt32(lastMatch.Groups[3].Value);

            // Extract match from memory.
            if (sizeToFileMap.TryGetValue(fileSize, out var fileInfoList))
            {
                var entry = RipUserSelectEntryFromList(fileInfoList);
                process.ReadRaw((IntPtr)(options.MinRamAddress + archiveOffset), out var file, entry.UncompressedSize);
                RipWriteFileToFolder(options.OutputPath, entry, file);
            }
            else
            {
                Console.WriteLine($"No known file in JSON found. Allowing game to advance.");
            }

            process.SafeWrite <int>((IntPtr)(options.MinRamAddress + dumpFlagAddr), 1);
        }