public void How2Dialog(MapCoordinate coor, int windowNum) { //获取当前地图 MoveBiz wbiz = new MoveBiz(windowNum); GameCommonUtil biz = new GameCommonUtil(); MapCoordinate nCoor = wbiz.GetNowMap(); bool flag = biz.CheckIsCloseToNPC(nCoor, coor); if (!flag) { //TODO,记录错误 return; } wbiz.PointPutToGameCoor(coor.coor); //先按F9,在Alt+H wbiz.PingBiPlayer(); WindowAPI.MMouseClick(1); Thread.Sleep(200); //checkDialog //Bitmap bm = PicUtil.GetScreen(); Point po = new Point(); //进入对话框了 if (!biz.HasDialogExist(windowNum, out po)) { Random ra = new Random(); int num = ra.Next(-1, 2); //没进入对话框 wbiz.MMoveRealCoor(num, num); How2Dialog(coor, windowNum); } }
/// <summary> /// 放到地图指定坐标, /// </summary> /// <param name="randomXS"></param> public void MPutToMapCoor(GameCoordinate targetGc, bool NeedGoThere) { Point po_nowdeskzuobiao = new Point(); string cityName = GetNowMap().CityName; City city = new City() { CityName = cityName, MapMaxGameCoor = new GameCoordinate(191, 119), MapSize = new int[2] { 441, 276 } }; po_nowdeskzuobiao = MPutToMayMapCenter(city, targetGc); if (NeedGoThere) { WindowAPI.MMouseClick(1); } try { MPutToMap(city, targetGc, NeedGoThere); } catch (HengTimeOutException ex) { if (ex.GetError() == "restart") { MPutToMapCoor(targetGc, NeedGoThere);//todo思考问题是否有 } } }
/// <summary> /// 检查toolName是否存在 /// </summary> /// <param name="toolName"></param> /// <returns></returns> public bool CheckToolsStatus(string toolName) { //移动鼠标到边上 MoveToConer(); string subPic = Singleton.GetInstance().PicRootDir + "tools\\" + toolName + ".png"; if (!File.Exists(subPic)) { log.Error("不存在路径" + subPic); return(false); } Bitmap bm = PicUtil.GetScreen(CenterPoint.X + 200, CenterPoint.Y + 40, 120, 200); List <Point> list = PicCorFinder.FindPicture(subPic, bm, Rectangle.Empty, 2); //没有被找到 if (list.Count == 0) { return(false); } else { Point p1 = Singleton.GetInstance().dicWindows[WindowNum].Point; WindowAPI.MMouseMoveTo(0, p1.X + 540, p1.Y - 170); return(true); } }
public void ActiveWindow() { Thread.Sleep(30); Point p1 = Singleton.GetInstance().dicWindows[WindowNum].Point; //窗口快速移动 WindowAPI.MMouseMoveTo(0, p1.X + StringUtil.GetRandomNum(320, 8), p1.Y - StringUtil.GetRandomNum(508, 2)); WindowAPI.MMouseClick(1); }
/// <summary> /// 必须是静止状态才可调用 /// </summary> public void MPutToPerson() { //线程休眠2秒,使得人物处于屏幕正中央! //TODO,需后续测试休眠时间,因为含图片计算等等耗费不少时间,所以初步预计一般2秒够了 //移动的时候肯定不准了 WindowAPI.MMouseMoveTo(0, CenterPoint.X, CenterPoint.Y); JiaoZhunMouse(true); Thread.Sleep(50); }
public void MMoveToRealCoor(int x, int y) { new GameCommonUtil().ThreadRest(2); PingBiPlayer(); //初始化目标地址 WindowAPI.MMouseMoveTo(0, CenterPoint.X + Singleton.GetInstance().GameBili *x, CenterPoint.Y + y * Singleton.GetInstance().GameBili); //校准偏差 JiaoZhunMouse(true); }
/// <summary> /// 如出现在边界外,获取该值的目标坐标并且返回可能的实际坐标值 /// </summary> /// <param name="po"></param> /// <param name="wantpo"></param> /// <param name="realpo"></param> /// <returns></returns> private void DoMove(GameCoordinate wantpo) { //确定移动的方向 int[] arr = { 0, 0 }; if (wantpo.X > (int)(548 / 2)) //x轴方向 { arr[0] = 1; //右移动 } else if (wantpo.X < (int)(548 / 2)) { arr[0] = -1;//左移动 } else { arr[0] = 0; //不移动 } if (wantpo.Y > (int)(278 / 2)) //y轴方向 { arr[1] = 1; //上移动 } else if (wantpo.Y < (int)(278 / 2)) { arr[1] = -1;//下移动 } else { arr[1] = 0;//不移动 } //推测4个象限的落点可能性 //TODO(是否需要判断多次),x轴右边的,则给他目标值偏差30px int x = 0; if (arr[0] > 0) { //TODO(548和1),对应地图移动距离 x = (548 - wantpo.X) * 1 - 30 * 1; } if (arr[0] < 0) { x = 30 * 1 - wantpo.X * 1; } int y = 0; if (arr[1] > 0) { //TODO(278和1),对应地图移动距离 y = -1 * ((278 - wantpo.Y) * 1 - 30 * 1); } if (arr[1] < 0) { x = -1 * (30 * 1 - wantpo.Y * 1); } //移动 WindowAPI.MMouseMove(0, x, y); }
public static int CallWndProc(int nCode, int wParam, IntPtr lParam) { var cwpStruct = Marshal.PtrToStructure <CWPStruct>(lParam); if (cwpStruct.message == WinMsgType.WM_COPYDATA) { var msgKind = cwpStruct.wParam; var copyData = Marshal.PtrToStructure <CopyDataStruct>(cwpStruct.lParam); CopyDataHandler(copyData); } return(WindowAPI.CallNextHookEx(_nextHook, nCode, wParam, lParam)); }
static async Task SetFokus(ProcessSD proc) { for (int i = 0; i < 5; i++) { try { WindowAPI.SetForegroundWindow(proc.MainWindowHandle); } catch {} await Task.Delay(1000); } }
private void OnLoaded(object sender, RoutedEventArgs e) { if (HwndControl.Hwnd != IntPtr.Zero && renderer == IntPtr.Zero) { WindowAPI.InitRenderer(HwndControl.Hwnd, out renderer); CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering); var spr = FindResource("WhitePixel") as BitmapImage; WindowAPI.RegisterTexture(renderer, "roaam_zone", System.AppDomain.CurrentDomain.BaseDirectory + spr.UriSource.LocalPath, 1, out var texture); LoadedImages["roaam_zone"] = new TexData(true, texture, WindowAPI.BitmapImageToBitmap(spr)); } }
/// <summary> ///人物请保持静止!!!往指定方向走一走,有1-2的误差! /// </summary> public void MMoveRealCoor(int x, int y) { ActiveWindow(); //先放到指定位置 MPutToPerson(); log.Info("防止正中央"); new GameCommonUtil().ThreadRest(2); PingBiPlayer(); //初始化目标地址 WindowAPI.MMouseMove(0, Singleton.GetInstance().GameBili *x, -y * Singleton.GetInstance().GameBili); //校准偏差 JiaoZhunMouse(false); }
private void FrmMsg_FormClosing(object sender, FormClosingEventArgs e) { WindowAPI.ShowWindow(this.Handle, 1); if (this.ExitApplication) { this.AbortThread(); } else { this.Hide(); e.Cancel = true; } }
/// <summary> /// Minimizes the specified window. /// </summary> /// <param name="hWnd"> /// A pointer to the window to minimize. /// </param> /// <returns> /// <c>true</c> if the specified window was successfully minimized; otherwise <c>false</c>. /// </returns> public static bool Minimize(IntPtr hWnd) { if (hWnd == IntPtr.Zero) { return(false); } if (WindowAPI.ShowWindowAsync(hWnd, ShowWindowCommand.SW_SHOWMINIMIZED)) { return(true); } return(false); }
/// <summary> /// /// </summary> /// <param name="pc"></param> public void JiaoZhunMouse(bool isAbsolute) { Point po = new Point(); WindowAPI.GetCursorPos(out po); ResetPC(); if (isAbsolute) { WindowAPI.MMouseMove(0, AbsolutePC[0], -AbsolutePC[1]); } else { WindowAPI.MMouseMove(0, RelativePC[0], -RelativePC[1]); } }
public static void SendDataMessage(IntPtr hwnd, byte[] messageData) { var copyData = new CopyDataStruct { cbData = 0, dwData = 0, lpData = IntPtr.Zero }; copyData.cbData = messageData.Length; copyData.lpData = Marshal.AllocHGlobal(messageData.Length); Marshal.Copy(messageData, 0, copyData.lpData, messageData.Length); WindowAPI.SendMessage(hwnd, WinMsgType.WM_COPYDATA, 0, ref copyData); Marshal.FreeHGlobal(copyData.lpData); }
/// <summary> /// 放到地图指定坐标TODO,少了个系数!!! /// </summary> /// <param name="randomXS"></param> private Point MPutToMayMapCenter(City city, GameCoordinate targetGc) { //20为误差阈值,其实阈值15已经很高了,不会超过20的! //计算预估坐标 //TODO 15这个觉得没什么大问题,测试多次能正确放置 int numX = (int)(city.MapMaxGameCoor.X / 15); int numY = (int)(city.MapMaxGameCoor.Y / 15); int x = 0; int y = 0; //如果4个点均是在内切20px范围的,直接转移进入 if (targetGc.X > numX && (Math.Abs(city.MapMaxGameCoor.X - targetGc.X) > numX)) { x = (int)((targetGc.X - city.MapCenterCoor.X) * city.XS) + CenterPoint.X; } else { if (targetGc.X <= numX) { x = (int)((targetGc.X - city.MapCenterCoor.X) * city.XS) + CenterPoint.X + (int)((numX - targetGc.X) * city.XS); } else { x = (int)((targetGc.X - city.MapCenterCoor.X) * city.XS) + CenterPoint.X - (int)((numX - city.MapMaxGameCoor.X + targetGc.X) * city.XS); } } if (targetGc.Y > numY && (Math.Abs(city.MapMaxGameCoor.Y - targetGc.Y) > numY)) { y = CenterPoint.Y - (int)((targetGc.Y - city.MapCenterCoor.Y) * city.XS); } else { if (targetGc.Y <= numY) { y = CenterPoint.Y - (int)((targetGc.Y - city.MapCenterCoor.Y) * city.XS) - (int)((numY - targetGc.Y) * city.XS); } else { y = CenterPoint.Y - (int)((targetGc.Y - city.MapCenterCoor.Y) * city.XS) + (int)((numY - city.MapMaxGameCoor.Y + targetGc.Y) * city.XS); } } //mayPoint = new Point(CenterPoint.X + targetGc.X - city.MapCenterCoor.X, city.MapCenterCoor.Y - targetGc.Y + CenterPoint.Y); WindowAPI.MMouseMoveTo(0, x, y); Thread.Sleep(100); return(new Point(x, y)); }
private void CompletionWindowOnClosed(object sender, EventArgs eventArgs) { UnbindCompletionWindowEventHandlers(); _completionWindow = null; _isClosing = false; if (_deactivateParentWindowOnCompletionWindowClose) { WithForm(delegate(Form form) { WindowAPI.SendMessage(form.Handle, WindowMessageType.WM_NCACTIVATE, new IntPtr(0), new IntPtr(0)); WindowAPI.SendMessage(form.Handle, WindowMessageType.WM_ACTIVATE, new IntPtr(0), new IntPtr(0)); }); _deactivateParentWindowOnCompletionWindowClose = false; } }
// ReSharper restore InconsistentNaming /// <summary> /// Displays a sort icon (up/down caret or chevron) on the given column. /// </summary> /// <param name="listViewControl"></param> /// <param name="columnIndex"></param> /// <param name="order"></param> /// <exception cref="Win32Exception"></exception> public static void SetSortIcon(this ListView listViewControl, int columnIndex, SortOrder order) { IntPtr columnHeader = WindowAPI.SendMessage(listViewControl.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero); for (int columnNumber = 0; columnNumber <= listViewControl.Columns.Count - 1; columnNumber++) { var columnPtr = new IntPtr(columnNumber); var item = new HDITEM { mask = HeaderItemMask.HDI_FORMAT }; if (WindowAPI.SendMessage(columnHeader, HDM_GETITEM, columnPtr, ref item) == IntPtr.Zero) { throw new Win32Exception(); } if (order != SortOrder.None && columnNumber == columnIndex) { switch (order) { case SortOrder.Ascending: item.fmt &= ~HeaderItemFormat.HDF_SORTDOWN; item.fmt |= HeaderItemFormat.HDF_SORTUP; break; case SortOrder.Descending: item.fmt &= ~HeaderItemFormat.HDF_SORTUP; item.fmt |= HeaderItemFormat.HDF_SORTDOWN; break; } } else { item.fmt &= ~HeaderItemFormat.HDF_SORTDOWN & ~HeaderItemFormat.HDF_SORTUP; } if (WindowAPI.SendMessage(columnHeader, HDM_SETITEM, columnPtr, ref item) == IntPtr.Zero) { throw new Win32Exception(); } } }
/// <summary> /// 获取所需用时 /// </summary> /// <param name="cityName"></param> /// <returns></returns> public int GetWalkSeconds(string cityName) { WindowAPI.MMouseMoveTo(0, 0, 0); Point p1 = Singleton.GetInstance().dicWindows[WindowNum].Point; Bitmap bm = PicUtil.GetScreen(p1.X, p1.Y - 480, 640, 480); //数点的个数,100px与等于15秒,ZZ100px约等于10点,1个点的时间2.3倍 //平均每个点为3.5/XS City city = new City() { CityName = cityName, MapMaxGameCoor = new GameCoordinate(191, 119), MapSize = new int[2] { 441, 276 } }; List <Point> list = PicCorFinder.FindPicture(Singleton.GetInstance().PicRootDir + "wp.png", bm, Rectangle.Empty, 2, 0.9, true); //额外加出3个点,防止几类情况 1、最后个棋子的挡住1个+自己一个2、大红点挡住一个 return((int)((list.Count + 3) * 3.5 / city.XS)); }
public TexData LoadImage(string name) { // Check if the sprite is loaded if (!LoadedImages.ContainsKey(name)) { // If spritename is set, attempt to load sprite bool hasSprite = false; hasSprite = WindowAPI.LoadImage(name, renderer, out TexData data); LoadedImages.Add(name, data); // If no sprite is found, use EmptyImage for this article if (!hasSprite) { BitmapImage overrideSpr = FindResource("EmptyImage") as BitmapImage; WindowAPI.RegisterTexture(renderer, name, AppDomain.CurrentDomain.BaseDirectory + overrideSpr.UriSource.LocalPath, 1, out int texture); LoadedImages[name] = new TexData(false, texture, null); } } return(LoadedImages[name]); }
/// <summary> /// 做了一堆容错,百度坑爹爹爹,相对稳定了 /// </summary> /// <returns></returns> private void MPutToMap(City city, GameCoordinate targetGC_JQ, bool NeedGoThere) { try { Point po_nowdeskzuobiao = new Point(); WindowAPI.GetCursorPos(out po_nowdeskzuobiao); //获取当前的游戏坐标 GameCoordinate nowGameCoor = MapOcr(city, targetGC_JQ); int x = targetGC_JQ.X - nowGameCoor.X; //要移动的距离 int y = targetGC_JQ.Y - nowGameCoor.Y; //要移动的距离 //获取到理想的地址 Point po_targetwdeskzuobiao = new Point((int)(po_nowdeskzuobiao.X + x * city.XS), (int)(po_nowdeskzuobiao.Y - y * city.XS)); //前往该地址 WindowAPI.MMouseMoveTo(0, po_targetwdeskzuobiao.X, po_targetwdeskzuobiao.Y); if (NeedGoThere) { WindowAPI.MMouseClick(1); } new GameCommonUtil().ThreadRest(2); //------------------ //截图 nowGameCoor = MapOcr(city, targetGC_JQ); if (nowGameCoor.X == -1) { Console.WriteLine("没颜色,重新来"); throw new HengTimeOutException("没颜色,重新来"); } if (Math.Abs(nowGameCoor.X - targetGC_JQ.X) < 3 && Math.Abs(nowGameCoor.Y - targetGC_JQ.Y) < 3) { Console.WriteLine("跳出"); return; } Console.WriteLine("进入循环 x::" + Math.Abs(nowGameCoor.X - targetGC_JQ.X) + "y:" + Math.Abs(nowGameCoor.Y - targetGC_JQ.Y)); //递归该方法 MPutToMap(city, targetGC_JQ, NeedGoThere); } catch (HengTimeOutException ex) { throw new HengTimeOutException(ex.GetError()); } }
private void FindSprites(object sender, RoutedEventArgs e) { var directory = Path.Combine(Path.GetDirectoryName(ApplicationSettings.Instance.ActiveProject.ProjectPath), "sprites"); Sprites.Clear(); foreach (var spriteFile in Directory.GetFiles(directory)) { var shortname = Path.GetFileNameWithoutExtension(spriteFile); var match = Regex.Match(shortname, "_strip\\d+"); if (match.Success) { shortname = shortname.Remove(match.Index); } if (!RoomEditor.Instance.LoadedImages.ContainsKey(shortname)) { WindowAPI.LoadImage(shortname, RoomEditor.Instance.renderer, out TexData data); RoomEditor.Instance.LoadedImages.Add(shortname, data); } Sprites.Add(shortname); } }
private void SetSize() { if (CurrentTileset != null && !string.IsNullOrEmpty(CurrentTileset.SpritePath)) { if (LoadedImages.ContainsKey(CurrentTileset.SpritePath)) { TexData spr = LoadedImages[CurrentTileset.SpritePath]; double ratio = (double)spr.image.Height / spr.image.Width; double adjustedHeight = ActualHeight / ratio; double maxDimension = Math.Min(ActualWidth, adjustedHeight); HwndControl.Width = maxDimension; HwndControl.Height = maxDimension * ratio; HwndControl.VerticalAlignment = VerticalAlignment.Top; if (renderer != IntPtr.Zero) { HRESULT.Check(WindowAPI.SetSize(renderer, (int)maxDimension, (int)(maxDimension * ratio))); } } } }
private async Task OnClickGame(string content, gridCellUser grid, TextBlock lblControl, ThicknessAnimation marginAnimation, DoubleAnimation fontAnimation) { if (false) { WindowAPI.SetWindowExTransparent(hwnd); } grid.contentGrid.IsEnabled = false; grid.contentGrid.BeginAnimation(MarginProperty, marginAnimation); lblControl.BeginAnimation(Label.FontSizeProperty, fontAnimation); var task = GameManager.RunGame(content); //if (isClickable) //{ // isClickable = false; // try // { // grid.contentGrid.BeginAnimation(MarginProperty, marginAnimation); // lblControl.BeginAnimation(Label.FontSizeProperty, fontAnimation); // var task = GameManager.RunGame(content); // } // catch (Exception ex) // { // Show(ex.Message); // isClickable = true; // } //} await Task.Delay(3000); grid.contentGrid.IsEnabled = true; //isClickable = true; if (false) { WindowAPI.RemoveWindowExTransparent(hwnd); } }
private void CompositionTarget_Rendering(object sender, EventArgs e) { RenderingEventArgs args = (RenderingEventArgs)e; if (_lastRender != args.RenderingTime) { SetSize(); if (CurrentTileset != null && !string.IsNullOrEmpty(CurrentTileset.SpritePath)) { TexData spr = LoadImage(CurrentTileset.SpritePath); DX_Article[] articles = new DX_Article[3]; int articles_count = 0; int tile_span = spr.image.Width / CurrentTileset.TileWidth; if (spr.image.Width % CurrentTileset.TileWidth != 0) { tile_span++; } int tile_depth = spr.image.Height / CurrentTileset.TileHeight; if (spr.image.Height % CurrentTileset.TileHeight != 0) { tile_depth++; } int lines_count = tile_span + tile_depth; DX_Line[] lines = new DX_Line[lines_count]; for (int i = 0; i < tile_span; i++) { lines[i] = new DX_Line( new Point(i * CurrentTileset.TileWidth, 0), new Point(i * CurrentTileset.TileWidth, spr.image.Height), 1, -1, WhiteBrush); } for (int i = 0; i < tile_depth; i++) { lines[tile_span + i] = new DX_Line( new Point(0, i * CurrentTileset.TileHeight), new Point(spr.image.Width, i * CurrentTileset.TileHeight), 1, -1, WhiteBrush); } articles[articles_count++] = new DX_Article(spr.texture, new Point(0, 0), new Point(1, 1), 0); var selected_x = (TilesetEditor.Instance.SelectedTile) % tile_span; var selected_y = (TilesetEditor.Instance.SelectedTile) / tile_span; articles[articles_count++] = new DX_Article(LoadedImages["roaam_zone"].texture, new Point(selected_x * CurrentTileset.TileWidth, selected_y * CurrentTileset.TileHeight), new Point(CurrentTileset.TileWidth, CurrentTileset.TileHeight), -1, unchecked ((int)0xAAFF8000)); var mousePos = Mouse.GetPosition(this); if (new Rect(0, 0, ActualWidth, ActualHeight).Contains(mousePos)) { int highlight_x = (int)((mousePos.X / (HwndControl.ActualWidth / spr.image.Width)) / CurrentTileset.TileWidth); int highlight_y = (int)((mousePos.Y / (HwndControl.ActualHeight / spr.image.Height)) / CurrentTileset.TileHeight); articles[articles_count++] = new DX_Article(LoadedImages["roaam_zone"].texture, new Point(highlight_x * CurrentTileset.TileWidth, highlight_y * CurrentTileset.TileHeight), new Point(CurrentTileset.TileWidth, CurrentTileset.TileHeight), -2, unchecked ((int)0xAAFFFFFF)); } WindowAPI.PrepareForRender(renderer); WindowAPI.SetCameraTransform(renderer, new Point(0, 0), (float)(HwndControl.ActualWidth / spr.image.Width)); WindowAPI.Render(renderer, articles, articles_count, lines, lines_count, null, 0); if (Mouse.LeftButton == MouseButtonState.Pressed) { var pos = GetMousePos(); if (pos != null) { TilesetEditor.Instance.SelectedTile = pos.Item1 + pos.Item2 * tile_span; } } } _lastRender = args.RenderingTime; } }
private void button2_Click(object sender, EventArgs e) { WindowAPI.SetWaitTick(10, 20, 20, 30); }
public static void Hook() { _nextHook = WindowAPI.SetWindowsHookExA(WinHookType.WH_CALLWNDPROC, SetWindowsHook, IntPtr.Zero, Process.GetCurrentProcess().Threads[0].Id); }
/// <summary> /// 屏蔽人员,毯子,F9 /// </summary> public void PingBiPlayer() { WindowAPI.MKeyDownUp(0, DeviceEnum.KeyBoardEnum.F9); WindowAPI.MZuHeKeyDownUp(0x40, DeviceEnum.KeyBoardEnum.h); }
public static void UnHook() { WindowAPI.UnhookWindowsHookEx(_nextHook); }
private void MoveToConer() { WindowAPI.MMouseMoveTo(0, 0, 0); }