コード例 #1
0
        public void Run(Process process)
        {
            _process = process;
            SetupInstance();
            var targetWnd = Managed.FindWindow(GameClass, GameName);

            Managed.SetForegroundWindow(targetWnd);
        }
コード例 #2
0
        private void SetupInstance()
        {
            _device = new D2DDevice(new DeviceOptions
            {
                AntiAliasing  = true,
                Hwnd          = _window.WindowHandle,
                MeasureFps    = true,
                MultiThreaded = false,
                VSync         = false
            });

            _procUtils = new ProcUtils(ProcessName,
                                       WinApi.ProcessAccessFlags.VirtualMemoryRead | WinApi.ProcessAccessFlags.VirtualMemoryWrite |
                                       WinApi.ProcessAccessFlags.VirtualMemoryOperation);
            MemUtils.Handle = _procUtils.Handle;

            _frameTimer = new FrameTimer(_device, 100);

            _window.OnWindowBoundsChanged += _window_OnWindowBoundsChanged;

            _initializeGraphicObjects = true;

            _frameTimer.OnFrameStarting += _frameTimer_OnFrameStarting;
            _frameTimer.OnFrame         += _frameTimer_OnFrame;

            _frameTimer.Start();
            Task.Run(async() =>
            {
                while (true)
                {
                    var targetWnd = Managed.FindWindow(GameClass, GameName);
                    if (targetWnd != IntPtr.Zero)
                    {
                        Managed.GetWindowRect(targetWnd, out var targetSize);

                        if (targetSize.Left < 0 && targetSize.Top < 0 && targetSize.Right < 0 &&
                            targetSize.Bottom < 0 ||
                            GetWindow() != ProcessName || !IsGameRun())
                        {
                            CanDraw = false;
                        }
                        else
                        {
                            CanDraw = true;
                        }
                    }
                    else
                    {
                        CanDraw = false;
                    }
                    await Task.Delay(500);
                }
            });

            LocalPlayer = new LocalPlayer();
            Players     = new List <Player>();
            for (var i = 0; i < MaxPlayersOnMap; i++)
            {
                var p = new Player(i);
                if (p.Entity == LocalPlayer.Entity)
                {
                    continue;
                }

                Players.Add(p);
            }

            Task.Run(async() =>
            {
                while (!IsInGame())
                {
                    await Task.Delay(500);
                }
                LocalPlayer.Update();
                Loaded();
            });
        }