/// <summary> /// Selects <see cref="WowProcess"/> from all available processes (via <see cref="WoWProcessSelector"/>). /// Checks selected process for <see cref="WowProcess.IsValidBuild"/> and <see cref="GameInterface.IsInGame"/> states. /// If something went wrong, informs user via Utils.NotifyUser(). /// </summary> /// <returns> /// Instance of <see cref="WowProcess"/> if successful, null otherwise /// </returns> internal static WowProcess GetProcess() { WowProcess wowProcess = WoWProcessSelector.GetWoWProcess(); if (wowProcess != null) { if (wowProcess.IsValidBuild) { if (new GameInterface(wowProcess).IsInGame) { if (wowProcess.Memory == null) { wowProcess.Memory = new MemoryManager(Process.GetProcessById(wowProcess.ProcessID)); } return(wowProcess); } log.Info($"{wowProcess} Player isn't logged in"); Notify.SmartNotify("Cannot attach to WoW client", "Player isn't logged in", NotifyUserType.Error, true); return(null); } else { log.Error($"{wowProcess} WoW client is outdated: {wowProcess.GetExecutableRevision()}"); Notify.SmartNotify("Cannot attach to WoW client", "AxTools is outdated. Please standby", NotifyUserType.Error, true); return(null); } } Notify.SmartNotify("Module error", "No WoW process found", NotifyUserType.Error, true); return(null); }
internal WoWAntiKick(WowProcess wowProcess) { this.wowProcess = wowProcess; info = new GameInterface(wowProcess); maxTime = Utils.Rnd.Next(150000, 290000); fallback_lastTimeActionEmulated = Environment.TickCount; timer = new System.Timers.Timer(2000); timer.Elapsed += Timer_Elapsed; timer.Start(); }
private static void ProcessWatcher_ProcessStarted(ProcessManagerEvent obj) { try { string processName = obj.ProcessName.ToLower(); if (processName == "wow.exe") { WowProcess wowProcess = new WowProcess(obj.ProcessId); Processes.TryAdd(obj.ProcessId, wowProcess); log.Info($"{wowProcess} Process started, {Processes.Count} total"); WoWProcessStartedOrClosed?.Invoke(); Task.Factory.StartNew(OnWowProcessStartup, wowProcess); } } catch (Exception ex) { log.Error($"[{obj.ProcessName}:{obj.ProcessId}] Process started with error: {ex.Message}"); } }
private static void GetWoWProcesses() { try { foreach (Process i in Process.GetProcesses()) { switch (i.ProcessName.ToLower()) { case "wow": WowProcess process = new WowProcess(i.Id); Processes.TryAdd(i.Id, process); log.Info($"{process} Process added"); Task.Factory.StartNew(OnWowProcessStartup, process); break; } } } catch (Exception ex) { log.Error($"{nameof(GetWoWProcesses)} error: {ex.Message}"); } }
private static void OnWowProcessStartup(object wowProcess) { try { WowProcess process = (WowProcess)wowProcess; log.Info($"{process} Attaching..."); for (int i = 0; i < 600; i++) { Thread.Sleep(100); if (process.MainWindowHandle != IntPtr.Zero) { if (Settings2.Instance.WoWCustomizeWindow) { Task.Run(() => { Thread.Sleep(1000); // because sometimes pause is needed try { if (Settings2.Instance.WoWCustomWindowNoBorder) { var styleWow = NativeMethods.GetWindowLong64(process.MainWindowHandle, Win32Consts.GWL_STYLE) & ~(Win32Consts.WS_CAPTION | Win32Consts.WS_THICKFRAME); NativeMethods.SetWindowLong64(process.MainWindowHandle, Win32Consts.GWL_STYLE, styleWow); } NativeMethods.MoveWindow(process.MainWindowHandle, Settings2.Instance.WoWCustomWindowRectangle.X, Settings2.Instance.WoWCustomWindowRectangle.Y, Settings2.Instance.WoWCustomWindowRectangle.Width, Settings2.Instance.WoWCustomWindowRectangle.Height, false); log.Info($"{process} Window style is changed"); } catch (Exception ex) { log.Error($"{process} Window changing failed with error: {ex.Message}"); } }); } try { Utils.SetProcessPrioritiesToNormal(process.ProcessID); // in case we'are starting from Task Scheduler priorities can be lower than normal process.Memory = new MemoryManager(Process.GetProcessById(process.ProcessID)); log.Info($"{process} Memory manager initialized, base address 0x{process.Memory.ImageBase.ToInt64():X}"); if (!process.IsValidBuild) { log.Info($"{process} Memory manager: invalid WoW executable"); Notify.TrayPopup("Incorrect WoW version", "Injector is locked, please wait for update", NotifyUserType.Warn, true); } WoWProcessReadyForInteraction?.Invoke(process); } catch (Exception ex) { log.Error($"{process} Memory manager initialization failed with error: {ex.Message}"); } break; } } } catch (Exception ex) { Processes.TryRemove((wowProcess as WowProcess).ProcessID, out WowProcess pWowProcess); pWowProcess?.Dispose(); log.Error($"{(wowProcess as WowProcess)}: {nameof(OnWowProcessStartup)}: general error: " + ex.Message); } }
private static void WoWProcessManager_WoWProcessReadyForInteraction(WowProcess obj) { instanses.Add(obj.ProcessID, new WoWAntiKick(obj)); }