示例#1
0
    private static int Start()
    {
        if (!File.Exists(Path.Combine(D2Path, D2Exe)) || !File.Exists(Path.Combine(Application.StartupPath, D2BSDLL)))
        {
            return(-1);
        }
        ProcessStartInfo processStartInfo = new ProcessStartInfo(Path.Combine(D2Path, D2Exe), " " + D2Args);

        processStartInfo.UseShellExecute  = false;
        processStartInfo.WorkingDirectory = D2Path;
        Process.EnterDebugMode();
        Process process = new Process();

        process.StartInfo = processStartInfo;
        process           = Kernel32.StartSuspended(process, processStartInfo);
        byte[] buffer = new byte[2];
        Kernel32.LoadRemoteLibrary(process, Path.Combine(D2Path, "D2Gfx.dll"));
        Kernel32.WriteProcessMemory(process, (IntPtr)1873327792, new byte[2]
        {
            235,
            69
        });
        IntPtr address = (IntPtr)1873327792;

        Kernel32.Resume(process);
        process.WaitForInputIdle();
        Kernel32.Suspend(process);
        Kernel32.WriteProcessMemory(process, address, buffer);
        Kernel32.Resume(process);
        Thread.Sleep(LoadDelay);
        Process[] childProcesses = ProcessExtensions.GetChildProcesses(process);
        if (childProcesses.Length > 0)
        {
            Process[] array = childProcesses;
            foreach (Process process2 in array)
            {
                if (IsD2Window(process2))
                {
                    process2.WaitForInputIdle();
                    return(process2.Id);
                }
            }
        }
        return(process.Id);
    }