public void CheckPossible(int processHandle, string input) { var buffer = new byte[0x10000]; uint bufferStart = 0; uint memoryPointer = 0; var possibleCount = 0; File.WriteAllText(input + ".txt", ""); while (memoryPointer < 0xFFFFFF00) { if (memoryPointer >= bufferStart + buffer.Length - (input.Length * 2) - 1) { MemoryUtil.Fill(processHandle, buffer, memoryPointer); bufferStart = memoryPointer; } if (IsPossible(input, buffer, memoryPointer - bufferStart)) { var outString = buffer.ToByteString((int)(memoryPointer - bufferStart), input.Length * 2); Console.WriteLine(outString); using (var writer = File.AppendText(input + ".txt")) { writer.WriteLine(outString); } possibleCount++; } memoryPointer++; } Console.WriteLine("READ TO: " + memoryPointer); Console.WriteLine("POSSIBLE: " + possibleCount); }
static void UpdateContent(int processPointer, byte[] dialogueMemory, uint memoryPointer, ref string content) { var newLines = GetContent(processPointer, dialogueMemory, memoryPointer); var newContent = String.Join("\n", newLines.Item2); if (newContent != content) { byte[] nearby = new byte[2048]; MemoryUtil.Fill(processPointer, nearby, memoryPointer - 512); File.WriteAllBytes("ed6_tmp.txt", nearby); //var search = MemoryUtil.Search(processPointer, query, 0x3000000, startIndex: memoryPointer); var search = MemoryUtil.Search(processPointer, query, 0x3000000, startIndex: memoryPointer); var fileIndex = 1; while (search != 0) { MemoryUtil.Fill(processPointer, nearby, search - 64); File.WriteAllBytes("ed6_tmp" + fileIndex + ".txt", nearby); //search = MemoryUtil.Search(processPointer, query, 0x3000000, startIndex: search + 64); search = MemoryUtil.Search(processPointer, query, 0x3000000, startIndex: search + 64); fileIndex++; } content = newContent; var outputContent = content; var stringBytes = Encoding.UTF8.GetBytes(outputContent); if (stringBytes.Length >= 2 && stringBytes[0] == 7) { //Console.WriteLine(Encoding.UTF8.GetBytes(content).ToByteString()); //outputContent = outputContent.Substring(2, outputContent.Length - 2); outputContent = Encoding.UTF8.GetString(stringBytes.SubArray(2, stringBytes.Length - 2)); // outputContent.Substring(3); } //Console.WriteLine(outputContent); //Console.WriteLine(Encoding.UTF8.GetBytes(content).ToByteString()); //Console.WriteLine(Encoding.UTF8.GetBytes(outputContent).ToByteString()); //Request.MakeRequest("http://localhost:1414/new-text?text=", "〜" + newLines.Item1 + "〜"); foreach (var line in newLines.Item2) { var outline = StripPrefix(line); var lineBytes = Encoding.UTF8.GetBytes(outline); if (lineBytes.Length >= 2 && stringBytes[0] == 7) { outline = Encoding.UTF8.GetString(stringBytes.SubArray(2, stringBytes.Length - 2)); } //Console.WriteLine("l:" + outline); Console.WriteLine(lineBytes.ToByteString()); File.WriteAllText("out_text.txt", outline); var requestText = CleanForRequest(outline); if (requestText != "\n" && requestText != "") { Request.MakeRequest("http://localhost:1414/new-text?text=", requestText); } } } }
public static byte[] GetActiveDialogue(int processPointer, uint memoryPointer) { //MemoryUtil.DumpSection("ed6d.txt", processPointer, memoryPointer - 64, 1024); var contentBuffer = new byte[DialogueBlockLength]; MemoryUtil.Fill(processPointer, contentBuffer, memoryPointer - BeforeDialogueBlockSize); return(contentBuffer); }
static Tuple <string, List <string> > GetContent(int processPointer, byte[] memory, uint memoryPointer) { var contentStrings = TextFormat.ExtractED6Text(memory, BeforeDialogueBlockSize); var nameBuffer = new byte[64]; MemoryUtil.Fill(processPointer, nameBuffer, memoryPointer + 1024 - 8); var nameString = TextFormat.ExtractED6Text(nameBuffer, 8)[0]; var strings = new List <string>(); foreach (var s in contentStrings) { strings.Add(s); } return(new Tuple <string, List <string> >(nameString, strings)); }
public static uint SearchDialogueStart(int processPointer) { //var search = MemoryUtil.Search(processPointer, query, 0x3000000, startIndex: 0x1180000); var search = MemoryUtil.Search(processPointer, query, 0x4000000, startIndex: 0x2A00000); MemoryUtil.Fill(processPointer, shortBuffer, search + 146); if (!ByteUtil.ByteCompare(isSpokenDialogueQuery, shortBuffer, 0)) { search = MemoryUtil.Search(processPointer, query, 0x4000000, startIndex: search + 302); MemoryUtil.Fill(processPointer, shortBuffer, search + 146); } Console.WriteLine("code: " + shortBuffer.ToByteString()); if (search != 0) { return(search + 302); } else { return(0); } }
public static void Main() { Console.OutputEncoding = Encoding.Unicode; //foreach(var p in Process.GetProcesses()) //{ // Console.WriteLine(p.ProcessName); //} //Process process = Process.GetProcessesByName("ePSXe")[0]; //Process process = Process.GetProcessesByName("ed6_win")[0]; //Process process = Process.GetProcessesByName("ed6_win_DX9")[0]; Process process = Process.GetProcessesByName("ed6_win2_DX9")[0]; IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id); int processPtr = (int)processHandle; //MemoryUtil.WriteMemoryStringsToFile(processPtr, "strings.txt"); //byte[] query = { 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x43 }; //byte[] query = Encoding.GetEncoding(932).GetBytes("エステル"); //byte[] query = Encoding.GetEncoding(932).GetBytes("シェラね"); //byte[] query = Encoding.GetEncoding(932).GetBytes("うーん"); //byte[] query = Encoding.GetEncoding(932).GetBytes("男性の声"); //byte[] query = Encoding.GetEncoding(932).GetBytes("カシウス"); //byte[] query = Encoding.GetEncoding(932).GetBytes("お、"); //byte[] query = Encoding.GetEncoding(932).GetBytes("男の子"); //byte[] query = Encoding.GetEncoding(932).GetBytes("おう"); //byte[] query = Encoding.GetEncoding(932).GetBytes("おとーさん"); byte[] query = Encoding.GetEncoding(932).GetBytes("いい子"); byte[] query2 = Encoding.GetEncoding(932).GetBytes("ふふん"); byte[] contentKey = new byte[query.Length]; byte[] content = new byte[256]; byte[] nearby = new byte[1024]; uint memoryPtr = 100000;//MemoryUtil.Search(processPtr, query); MemoryUtil.DumpSection("found.txt", processPtr, memoryPtr - 0x1000, 0x2000); Console.WriteLine(memoryPtr); //var memoryPtr2 = MemoryUtil.Search(processPtr, query2); //Console.WriteLine(memoryPtr2); //Console.ReadLine(); //return; ED6Util.ED6Monitor(processPtr); while (true) { if (memoryPtr == 0) { System.Threading.Thread.Sleep(51); continue; } //var contentPointer = (uint)(memoryPtr + query.Length + contentOffset); var contentPointer = memoryPtr; MemoryUtil.Fill(processPtr, content, contentPointer); MemoryUtil.Fill(processPtr, contentKey, memoryPtr); MemoryUtil.Fill(processPtr, nearby, memoryPtr - 16); MemoryUtil.HandleContent(content); File.WriteAllBytes("content.txt", content); File.WriteAllBytes("tmp.txt", nearby); Console.Write("string: "); var lines = TextFormat.ExtractED6Text(nearby, 16); foreach (var line in lines) { Console.WriteLine(line); Request.MakeRequest("http://localhost:1414/new-text?text=", line); } //var processId = Process.GetProcessesByName("ed6_win")[0].Id; //ProcessExtension.Suspend(processId); //FocusThis(); //Console.WriteLine("Press enter to continue..."); //Console.ReadLine(); //ProcessExtension.Resume(processId); //FocusProcess(processId); var handleIsSame = MemoryUtil.SearchAtPointer(processPtr, contentKey, memoryPtr); var contentIsSame = MemoryUtil.SearchAtPointer(processPtr, content, contentPointer); while (handleIsSame && contentIsSame) { System.Threading.Thread.Sleep(50); handleIsSame = MemoryUtil.SearchAtPointer(processPtr, contentKey, memoryPtr); contentIsSame = MemoryUtil.SearchAtPointer(processPtr, content, contentPointer); } Console.WriteLine("handle same: " + handleIsSame + "; content same: " + contentIsSame); } Console.ReadLine(); }
public static void ED6Monitor(int processPointer) { var ed6DialogueStart = SearchDialogueStart(processPointer); Console.WriteLine("NEW HEAD IS: " + ed6DialogueStart.ToString("X4")); var currentDialogue = GetActiveDialogue(processPointer, ed6DialogueStart); var buffer = new byte[currentDialogue.Length]; var visibleBuffer = new byte[2]; var newVisisbleBuffer = new byte[2]; MemoryUtil.Fill(processPointer, visibleBuffer, DialogueMemoryPointerToVisibleMemoryPointer(ed6DialogueStart)); Console.WriteLine(visibleBuffer.ToByteString()); var content = ""; UpdateContent(processPointer, currentDialogue, ed6DialogueStart, ref content); //Thread visibilityListener = new Thread(() => //{ // while (true) // { // MemoryUtil.Fill(processPointer, newVisisbleBuffer, DialogueMemoryPointerToVisibleMemoryPointer(ed6DialogueStart)); // if (visibleBuffer[0] != newVisisbleBuffer[0] || visibleBuffer[1] != newVisisbleBuffer[1]) // { // Console.WriteLine("V>>>>>>>>>>>> " + newVisisbleBuffer.ToByteString()); // visibleBuffer[0] = newVisisbleBuffer[0]; // visibleBuffer[1] = newVisisbleBuffer[1]; // Thread.Sleep(7); // } // } //}); //visibilityListener.Start(); while (true) { System.Threading.Thread.Sleep(978); ed6DialogueStart = SearchDialogueStart(processPointer); currentDialogue = GetActiveDialogue(processPointer, ed6DialogueStart); UpdateContent(processPointer, currentDialogue, ed6DialogueStart, ref content); //MemoryUtil.Fill(processPointer, newVisisbleBuffer, DialogueMemoryPointerToVisibleMemoryPointer(ed6DialogueStart)); //if (visibleBuffer[0] != newVisisbleBuffer[0] || visibleBuffer[1] != newVisisbleBuffer[1]) //{ // Console.WriteLine("VISIBLE: " + newVisisbleBuffer.ToByteString()); // visibleBuffer[0] = newVisisbleBuffer[0]; // visibleBuffer[1] = newVisisbleBuffer[1]; // if (visibleBuffer[0] == 0 || visibleBuffer[1] == 0) // { // Console.WriteLine("SEEKING NEW HEAD..."); // uint newStart = 0; // while (newStart == 0) // { // newStart = SearchDialogueStart(processPointer); // Thread.Sleep(50); // } // Console.WriteLine("NEW HEAD IS: " + newStart.ToString("X4")); // ed6DialogueStart = newStart; // currentDialogue = GetActiveDialogue(processPointer, ed6DialogueStart); // UpdateContent(processPointer, currentDialogue, ed6DialogueStart, ref content); // } //} //while (!MemoryUtil.HasMemoryChanged(processPointer, currentDialogue, buffer, ed6DialogueStart - BeforeDialogueBlockSize)) //{ // System.Threading.Thread.Sleep(50); //} //currentDialogue = GetActiveDialogue(processPointer, ed6DialogueStart); //UpdateContent(processPointer, currentDialogue, ed6DialogueStart, ref content); } }