Exemplo n.º 1
0
        private static void ProcessThreadMethod()
        {
            // Process watcher thread
            while (ProcessThread.ThreadState == ThreadState.Running)
            {
                if (GameProcess == null)
                {
                    try
                    {
                        // Acquire a list of all processes
                        var wowProcess =
                            Process.GetProcesses()
                            .FirstOrDefault(
                                process =>
                                WoWProcessNames.Contains(process.ProcessName.ToLower()) &&
                                process.HasExited == false);

                        if (wowProcess != null)
                        {
                            GameProcess = wowProcess;

                            Log.WriteLine($"Found game process: [{GameProcess.Id}: {GameProcess.ProcessName}]");

                            // Attempt to export bindings
                            ConsolePort.BindWriter.WriteBinds();

                            if (Properties.Settings.Default.EnableMemoryReading) // Attach memory reader
                            {
                                WoWReader.Open(wowProcess);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLine($"Exception occurred: {ex.Message}");
                    }
                }

                if (GameProcess != null)
                {
                    // Test process validity
                    if (GameProcess.HasExited)
                    {
                        Log.WriteLine($"Process [{GameProcess.Id}: {GameProcess.ProcessName}] has exited");

                        GameProcess.Dispose();
                        GameProcess = null;
                        continue;
                    }

                    // Attach/detach memory reader as necessary
                    if (Properties.Settings.Default.EnableMemoryReading && !WoWReader.IsAttached)
                    {
                        WoWReader.Open(GameProcess);
                    }

                    if (!Properties.Settings.Default.EnableMemoryReading && WoWReader.IsAttached)
                    {
                        WoWReader.Close();
                    }
                }

                Thread.Sleep(500);
            }
        }
Exemplo n.º 2
0
 internal static void Stop()
 {
     WoWReader.Close();
     _threadRunning = false;
     ProcessThread.Abort();
 }