private void BtnStart_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(PathToExe)) { Stopwatch sw = new Stopwatch(); sw.Start(); (bool, PROCESS_INFORMATION)data = ProcessStart.StartProcess(PathToExe, ProcessCreationFlags.ZERO_FLAG); if (data.Item1) { Process Genshin = Process.GetProcesses().ToList().Find((p) => p.ProcessName == "GenshinImpact"); if (Genshin != null) { try { Thread.Sleep(1000); string path = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "HelloWorldDLL.dll"); if (!File.Exists(path)) { throw new ApplicationException($"Code: {path} does not exists"); } IntPtr threadAddress = DLLInjection.Inject(Genshin, path); ProcessExtensions.NativeMethods.CloseHandle(threadAddress); sw.Stop(); lblTime.Text = $"{sw.Elapsed.Seconds}:{sw.Elapsed.Milliseconds}"; if (threadAddress != IntPtr.Zero) { ProcessExtensions.Resume(Genshin, threadAddress); } else { throw new ApplicationException($"Code: {Marshal.GetLastWin32Error()}"); } } catch (ApplicationException ex) { MessageBox.Show("ERROR:\n" + ex.Message); } finally { ProcessExtensions.NativeMethods.CloseHandle(data.Item2.hProcess); } } else { MessageBox.Show("ERROR: FAILED TO GET GENSHIN PROCESS"); } } } }
private void BtnStart_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(PathToExe)) { Stopwatch sw = new Stopwatch(); sw.Start(); (bool, PROCESS_INFORMATION)data = ProcessStart.StartProcess(PathToExe, ProcessCreationFlags.ZERO_FLAG); if (data.Item1) { Process genshin = Process.GetProcesses().ToList().Find((p) => p.ProcessName == "GenshinImpact"); if (genshin != null) { try { //string path = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "HelloWorldDLL.dll"); //if(!File.Exists(path)) throw new ApplicationException($"Code: {path} does not exists"); IntPtr procHandle = DLLInjection.OpenProcess(genshin); if (IntPtr.Zero == procHandle) { throw new ApplicationException($"Code: procHandle has value 0x{procHandle}"); } ProcHandle = procHandle; Genshin = genshin; ProcessExtensions.Resume(Genshin); } catch (ApplicationException ex) { MessageBox.Show("ERROR:\n" + ex.Message); } finally { ProcessExtensions.NativeMethods.CloseHandle(data.Item2.hProcess); } } else { MessageBox.Show("ERROR: FAILED TO GET GENSHIN PROCESS"); } } } }