/// <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); }
private static void Rip(RipOptions options) { using var fileStream = new FileStream(options.LogPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); fileStream.Seek(0, SeekOrigin.End); var buffer = new byte[10000]; Console.WriteLine("Beginning AutoRip, CTRL+C to Exit."); while (true) { var streamPos = fileStream.Position; var bytesSinceLastUpdate = fileStream.Length - streamPos; // Resize buffer if necessary. if (bytesSinceLastUpdate > buffer.Length) { buffer = new byte[bytesSinceLastUpdate]; } // Read new log text. fileStream.Read(buffer); var text = Encoding.UTF8.GetString(buffer); // RIP if there is new error text. if (text.Contains("Addr:")) { NewRip(options); Array.Fill <byte>(buffer, 0x00); } else { fileStream.Position = streamPos; } Thread.Sleep(200); } }