封装的有问题 其中方框可能在别的方向可能 会显示不出来建议不要下载了 抽时间我会用纯c#写一个例子的
其中绘制方框文字和直线调用的外部dll采用DX11(不吃CUP)绘制我封装成了DLL命名为 SoftwareHelper.dll 把他和你软件放置同一目录调用即可
其中dll是易语言调用别人DX11模块编译的(采用黑月编译体积小不容易报毒)封装了一些基本功能 需要的请自行添加 易语言代码如下(相关文件我将会传上去)
.版本 2 .程序集 程序集1 .子程序 _启动子程序, 整数型, , 请在本子程序中放置动态链接库初始化代码 _临时子程序 () ' 在初始化代码执行完毕后调用测试代码 返回 (0) ' 返回值被忽略。 .子程序 _临时子程序 ' 本名称子程序用作测试程序用,仅在开发及调试环境中有效,编译发布程序前将被系统自动清空,请将所有用作测试的临时代码放在本子程序中。 ***注意不要修改本子程序的名称、参数及返回值类型。 .子程序 InitDX11, , 公开, 初始化成功为真 否则 为假 .参数 字体大小, 整数型, , 默认17 初始化Dx11 (字体大小) .子程序 SafetyQuit, , 公开, 退出调用 安全退出 () .子程序 SetWindowPos_Top, 逻辑型, 公开, 设置窗口在最顶端,成功返回真,失败返回假 .参数 handle, 整数型, , 欲设置的窗口句柄 返回 (窗口_置顶 (handle)) .子程序 MoveWindows, , 公开, 移动指定窗口(无返回值) .参数 handle, 整数型, , 欲移动窗口的句柄 .参数 newleft, 整数型, , 可空:原左边不变 .参数 newtop, 整数型, , 可空:原顶边不变 .参数 newwidth, 整数型, , 可空:原宽度不变 .参数 newheight, 整数型, , 可空:原高度不变 窗口移动 (handle, newleft, newtop, newwidth, newheight) .子程序 DrawText, , 公开 .参数 X, 整数型 .参数 Y, 整数型 .参数 text, 文本型 .参数 color, 整数型 绘制文本 (X, Y, text, color, ) .子程序 DrawLine, , 公开 .参数 开始X, 整数型 .参数 开始Y, 整数型 .参数 结束x, 整数型 .参数 结束y, 整数型 .参数 线宽, 整数型 .参数 颜色, 整数型 绘制直线 (开始X, 开始Y, 结束x, 结束y, 线宽, 颜色, ) .子程序 ProcessIsExist, 逻辑型, 公开, 判断指定进程是否存在(此判断与进程其它信息无关联)(存在返回真,不存在或失败返回假) .参数 进程名, 文本型, , 欲检测的进程名(不区分大小写) 返回 (进程是否存在 (进程名)) .子程序 DrawSquare, , 公开 .参数 X, 整数型 .参数 Y, 整数型 .参数 W, 整数型 .参数 H, 整数型 .参数 外框颜色, 整数型 .参数 内框颜色, 整数型 .参数 线宽, 整数型 描边方框 (X, Y, W, H, 外框颜色, 内框颜色, 线宽, ) .子程序 GetDX11CreateWindowHandle, 整数型, 公开, (这两个参数不用填一般也能取到)为了防止重复和枚举窗口名称为 DX11t?h?i?s? ?i?s? ?y?o?u? ?w?i?n?d?o?w? 返回 (取DX11创建的透明窗口句柄 (, )) .子程序 OptimizeCUP, , 公开, 优化cpu .参数 时间, 整数型, , 毫秒 优化CUP (时间) .子程序 OptimizeDelayed, , 公开, 优化延时 .参数 时间, 整数型, , 毫秒 优化延时 (时间) .子程序 OptimizeSystem, , 公开, 比普通的处理事件速度要快3倍左右; 系统_处理事件 () .子程序 StartDrawing, , 公开 开始绘图 () .子程序 EndDrawing, , 公开 结束绘图 () .子程序 MouseMoveInGame, , 公开, SendInput模拟鼠标移动(无返回值)目标坐标与实际坐标有一像素点误差属正常现象! .参数 窗口句柄, 整数型, , 可空:相对桌面移动鼠标 句柄有效则相对窗口中坐标移动 .参数 水平坐标, 整数型 .参数 垂直坐标, 整数型 鼠标移动2 (窗口句柄, 水平坐标, 垂直坐标)
c# 调用dll封装类
class DllHelper { public const int COLORBLACK = 0;//黑色 public const int COLORWHITE = 16777215;//#白色 public const int COLORPINKISHRED = 16711935;//#品红 public const int COLORCYAN = 8388608;//#藏青 public const int COLORGREEN = 32768;//#墨绿 public const int COLORDEEPCYAN = 8421376;//#深青 public const int COLORYELLOW = 65535;//#黄色 public const int COLORBLUE = 16711680;//#蓝色 public const int COLORRED = 255;//#红色 public const int COLOGRAY = 8421504;//#灰色 public const int COLOORANGE = 33023;//#橙黄 [DllImport("SoftwareHelper.dll", EntryPoint = "InitDX11")] public static extern void InitDX11(int wordsize);//初始化一个dx11透明窗口参数为字体大小建议15 [DllImport("SoftwareHelper.dll", EntryPoint = "SafetyQuit")] public static extern void SafetyQuit();//安全退出放在窗口是否可以被关闭事件卸载绘图 [DllImport("SoftwareHelper.dll", EntryPoint = "SetWindowPos_Top")] public static extern bool SetWindowPos_Top(int handle);//设置窗口置顶参数为窗口句柄 [DllImport("SoftwareHelper.dll", EntryPoint = "MoveWindows")] public static extern void MoveWindows(int handle,int newleft,int newtop,int newwidth,int newheight);//移动窗口 窗口句柄 窗口左边 窗口顶部 窗口高度宽度 [DllImport("SoftwareHelper.dll", EntryPoint = "DrawText")]//写字 public static extern void DrawText(int X, int Y, string text, int color); //屏幕xy 和文本 颜色用上面定义的常量 [DllImport("SoftwareHelper.dll", EntryPoint = "DrawLine")]//画线 public static extern void DrawLine(int X, int Y, int Xend, int Yend, int linePx, int color);//x为开始x坐标 x1为结束x坐标 linepx为线宽度 颜色用上面定义的常量 [DllImport("SoftwareHelper.dll", EntryPoint = "ProcessIsExist")]//判断指定进程是否存在(此判断与进程其它信息无关联)(存在返回真,不存在或失败返回假) public static extern bool ProcessIsExist(string processname);//进程名称带后zhui [DllImport("SoftwareHelper.dll", EntryPoint = "DrawSquare")]//画出描边方框 public static extern void DrawSquare(int X, int Y, int W, int H ,int colorout, int colorin,int linepx);//colorout外部方框颜色 in为内部 linepx线宽 [DllImport("SoftwareHelper.dll", EntryPoint = "GetDX11CreateWindowHandle")]//得到对象dx11创建的透明窗口句柄 为了防止重复和游戏 枚举窗口名称为 DX11t?h?i?s? ?i?s? ?y?o?u? ?w?i?n?d?o?w? public static extern int GetDX11CreateWindowHandle(); [DllImport("SoftwareHelper.dll", EntryPoint = "OptimizeCUP")]//优化cup防止绘制卡 public static extern void OptimizeCUP(int time);//毫秒 [DllImport("SoftwareHelper.dll", EntryPoint = "OptimizeDelayed")]//优化延时 public static extern void OptimizeDelayed(int time);//毫秒 [DllImport("SoftwareHelper.dll", EntryPoint = "OptimizeSystem")]//系统处理事件同样是为了优化cup防止卡 public static extern void OptimizeSystem(); [DllImport("SoftwareHelper.dll", EntryPoint = "StartDrawing")]//开始绘图 绘图前调用 public static extern void StartDrawing(); [DllImport("SoftwareHelper.dll", EntryPoint = "EndDrawing")]//结束绘图 绘图结束调用 public static extern void EndDrawing(); [DllImport("SoftwareHelper.dll", EntryPoint = "MouseMoveInGame")]//鼠标可以在游戏内移动游戏外部自瞄调用 public static extern void MouseMoveInGame(int handle,int x,int y);//游戏窗口句柄 xy坐标 }
c#内存辅助类
class GameUtil { public struct RECT { public int Left; //最左坐标 public int Top; //最上坐标 public int Right; //最右坐标 public int Bottom; //最下坐标 } public struct RECTClient { public uint Left; public uint Top; public uint Right; public uint Bottom; } public struct LPPOINT { public int x; public int y; } [DllImport("kernel32.dll", EntryPoint = "ReadProcessMemory")] public static extern int _MemoryReadByteSet(int hProcess, int lpBaseAddress, byte[] lpBuffer, int nSize, int lpNumberOfBytesRead); [DllImport("kernel32.dll", EntryPoint = "ReadProcessMemory")] public static extern int _MemoryReadInt32(int hProcess, int lpBaseAddress, ref int lpBuffer, int nSize, int lpNumberOfBytesRead); [DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")] public static extern int _MemoryWriteByteSet(int hProcess, int lpBaseAddress, byte[] lpBuffer, int nSize, int lpNumberOfBytesWritten); [DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")] public static extern int _MemoryWriteInt32(int hProcess, int lpBaseAddress, ref int lpBuffer, int nSize, int lpNumberOfBytesWritten); [DllImport("kernel32.dll", EntryPoint = "GetCurrentProcess")] public static extern int GetCurrentProcess(); [DllImport("kernel32.dll", EntryPoint = "OpenProcess")] public static extern int OpenProcess(int dwDesiredAccess, int bInheritHandle, int dwProcessId); [DllImport("kernel32.dll", EntryPoint = "CloseHandle")] public static extern int CloseHandle(int hObject); [DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")] public static extern int _CopyMemory_ByteSet_Float(ref float item, ref byte source, int length); const int PROCESS_POWER_MAX = 2035711; [DllImport("kernel32.dll")] public static extern bool ReadProcessMemory(IntPtr hProcess, int lpBaseAddress, byte[] lpBuffer, uint nSize, out int lpNumberOfBytesRead); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect); [DllImport("user32")] public static extern bool GetClientRect(IntPtr hwnd,out RECTClient lpRect ); [DllImport("user32")] public static extern bool ClientToScreen(IntPtr hwnd, out LPPOINT point); //打开进程 //kernel32.dll系统动态链接库 [DllImportAttribute("kernel32.dll", EntryPoint = "OpenProcess")] public static extern IntPtr OpenProcess ( int iAccess, bool Handle, int ProcessID ); //关闭句柄 [DllImport("kernel32.dll", EntryPoint = "CloseHandle")] private static extern void CloseHandle ( IntPtr hObject ); //取窗口句柄 FindWindow [DllImport("User32.dll", EntryPoint = "FindWindow")] public extern static IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("User32.dll", EntryPoint = "FindWindowEx")] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName); //移动窗口 /// <summary> /// 设置目标窗体大小,位置 /// </summary> /// <param name="hWnd">目标句柄</param> /// <param name="x">目标窗体新位置X轴坐标</param> /// <param name="y">目标窗体新位置Y轴坐标</param> /// <param name="nWidth">目标窗体新宽度</param> /// <param name="nHeight">目标窗体新高度</param> /// <param name="BRePaint">是否刷新窗体</param> /// <returns></returns> [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint); //--------------------------------------------------------------------------------------------------------------- /// <summary> /// 读内存整数型 /// </summary> /// <param name="pID">进程ID</param> /// <param name="bAddress">0x地址</param> /// <returns>0失败</returns> public static int ReadMemoryInt32(int pID, int bAddress) { int num = 0; int handle = getProcessHandle(pID); int num3 = GameUtil._MemoryReadInt32(handle, bAddress, ref num, 4, 0); GameUtil.CloseHandle(handle); if (num3 == 0) { return 0; } else { return num; } } /// <summary> /// 写内存整数型 /// </summary> /// <param name="pID">进程ID</param> /// <param name="bAddress">0x地址</param> /// <param name="value">写入值</param> /// <returns>false失败 true成功</returns> public static bool WriteMemoryInt32(int pID, int bAddress, int value) { int handle = getProcessHandle(pID); int num2 = GameUtil._MemoryWriteInt32(handle, bAddress, ref value, 4, 0); GameUtil.CloseHandle(handle); return num2 != 0; } /// <summary> /// 读内存小数型 /// </summary> /// <param name="pID">进程ID</param> /// <param name="bAddress">0x地址</param> /// <returns>0失败</returns> public static float ReadMemoryFloat(int pID, int bAddress) { //byte[] array = test.GetVoidByteSet(4); byte[] array = new byte[4];//不取空字节集也可以正确转换成单精度小数型 int handle = getProcessHandle(pID); int temp = GameUtil._MemoryReadByteSet(handle, bAddress, array, 4, 0); if (temp == 0) { return 0f; } else { return GameUtil.getFloatFromByteSet(array, 0); } } /// <summary> /// 写内存小数型 /// </summary> /// <param name="pID">进程ID</param> /// <param name="bAddress">0x地址</param> /// <param name="value">写入数据</param> /// <returns>false失败</returns> public static bool WriteMemoryFloat(int pID, int bAddress, float value) { //byte[] byteSet = test.GetByteSet(value); byte[] byteSet = BitConverter.GetBytes(value);//https://msdn.microsoft.com/en-us/library/yhwsaf3w //byte[] byteSet = Encoding.GetEncoding("gb2312").GetBytes(value.ToString()); return GameUtil.WriteMemoryByteSet(pID, bAddress, byteSet, 0); } /// <summary> /// 写内存字节集 /// </summary> /// <param name="pID">进程ID</param> /// <param name="bAddress">0x地址</param> /// <param name="value">字节数据</param> /// <param name="length">写入长度 0代表字节数据的长度</param> /// <returns>false失败</returns> private static bool WriteMemoryByteSet(int pID, int bAddress, byte[] value, int length = 0) { int handle = GameUtil.getProcessHandle(pID); int nSize = (length == 0) ? value.Length : length; int tmp = GameUtil._MemoryWriteByteSet(handle, bAddress, value, nSize, 0);//byte[]属于引用类型 引用类型不用ref也是以传址方式进行运算 //test.CloseHandle(pID); return tmp != 0; } /// <summary> /// 取空白字节集 /// </summary> /// <param name="num"></param> /// <returns></returns> public static byte[] getVoidByteSet(int num) { if (num <= 0) { num = 1; } string text = ""; for (int i = 0; i < num; i++) { text += "0"; } return Encoding.UTF8.GetBytes(text); } /// <summary> /// 取进程句柄 /// </summary> /// <param name="pID">进程ID</param> /// <returns>进程句柄</returns> public static int getProcessHandle(int pID) { if (pID == -1) { return GameUtil.GetCurrentProcess(); } else { return GameUtil.OpenProcess(PROCESS_POWER_MAX, 0, pID); } } /// <summary> /// 字节集转小数型 /// </summary> /// <param name="sourceValue">字节集</param> /// <param name="index">索引</param> /// <returns></returns> public static float getFloatFromByteSet(byte[] sourceValue, int index) { float result = 0f; GameUtil._CopyMemory_ByteSet_Float(ref result, ref sourceValue[index], 4); return result; } /// <summary> /// 获取字节集 /// </summary> /// <param name="data">需要转换到字节集的数据</param> /// <returns></returns> public static byte[] getByteSet(float data) { return Encoding.UTF8.GetBytes(data.ToString()); } //根据名称取进程PID 不得有后缀.exe //根据进程名获取PID 不得有后缀.exe public static int getPidByProcessName(string processName) { Process[] ArrayProcess = Process.GetProcessesByName(processName); foreach (Process pro in ArrayProcess) { return pro.Id; } return 0; } //获取模块地址 public static int getMoudleAddress(string processName ,string dllname ) { foreach (Process p in Process.GetProcessesByName(processName)) { foreach (ProcessModule m in p.Modules) { if (m.ModuleName.Equals(dllname)) return (int)m.BaseAddress; } } return 0; } //取窗口句柄 这里传入的值是窗口标题 public static IntPtr getWindowsHandler_findwindow(String classname,String windowtitle) { IntPtr maindHwnd = FindWindow(classname, windowtitle); //获得QQ登陆框的句柄 return maindHwnd; } public static RECT getWindowsRect(IntPtr windowsHandler) { RECT rec = new RECT(); GetWindowRect(windowsHandler, ref rec);//h为窗口句柄 return rec; } }
窗口类c#
public partial class Form1 : Form { int PID; int matrix;//矩阵基质 float formwidth;//窗口宽度 float formheight;//窗口高度 int processmoudle;//进程模块; IntPtr windowshandle;//窗口句柄 int dx11hwnd;//dx11创建的透明窗口句柄 private void loop()//循环 { while (true) { Util.DllHelper.OptimizeCUP(2);//防止占用cpu reflushWindows(); startDrawit(); Util.DllHelper.OptimizeDelayed(1);//防止占用cpu } } private void intData() { PID= Util.GameUtil.getPidByProcessName("cstrike"); windowshandle=Util.GameUtil.getWindowsHandler_findwindow("Valve001", "Counter-Strike"); processmoudle=Util.GameUtil.getMoudleAddress("cstrike", "cstrike.exe"); matrix = processmoudle + 25297152; formwidth= Util.GameUtil.getWindowsRect(windowshandle).Right - Util.GameUtil.getWindowsRect(windowshandle).Left; formheight= Util.GameUtil.getWindowsRect(windowshandle).Bottom - Util.GameUtil.getWindowsRect(windowshandle).Top; //this.ShowInTaskbar = false;//任务栏显示为假 Debug.Print(PID + "PID" + "windowshandle" + windowshandle + "matrix" + matrix + "formwidth" + formwidth + "formheight" + formheight); } private void startIt() { Util.DllHelper.InitDX11(14);//初始化dx11 dx11hwnd = Util.DllHelper.GetDX11CreateWindowHandle();//取得dx11创建的透明窗口的句柄 if (dx11hwnd == 0) MessageBox.Show("DX11加载失败"); else MessageBox.Show("DX11加载成功"); reflushWindows(); loop(); } private void startDrawit() { Util.DllHelper.StartDrawing();//开始绘图 Util.DllHelper.DrawText(0, 0, "C#dx11", Util.DllHelper.COLORYELLOW); worldtoScreen(); Util.DllHelper.EndDrawing();//结束绘图 } private void worldtoScreen()//游戏世界转屏幕 { float arr00 = Util.GameUtil.ReadMemoryFloat(PID, matrix); float arr01 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 4); float arr02 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 8); float arr03 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 12); float arr10 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 16); float arr11 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 20); float arr12 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 24); float arr13 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 28); float arr20 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 32); float arr21 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 36); float arr22 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 40); float arr23 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 44); float arr30 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 48); float arr31 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 52); float arr32 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 56); float arr33 = Util.GameUtil.ReadMemoryFloat(PID, matrix + 60); //得到矩阵所有值 float sightwidth = formwidth / 2;//视角宽 float sightheight = formheight / 2;//视角高 float enemy_x = Util.GameUtil.ReadMemoryFloat(PID, processmoudle + 17369300 - 8); float enemy_y = Util.GameUtil.ReadMemoryFloat(PID, processmoudle + 17369300 - 4); float enemy_z = Util.GameUtil.ReadMemoryFloat(PID, processmoudle + 17369300); float camera_Z = arr02 * enemy_x + arr12 * enemy_y + arr22 * enemy_z + arr32; if (camera_Z <= 0.01) return; float zoom = 1 / camera_Z;//缩放比例 float camera_x = sightwidth + (arr00 * enemy_x + arr10 * enemy_y + arr20 * enemy_z + arr30) * zoom * sightwidth; float camera_y = sightheight - (arr01 * enemy_x + arr11 * enemy_y + arr21 * (enemy_z + 30) + arr31) * zoom * sightheight * 1; float camera_y2 = sightheight - (arr01 * enemy_x + arr11 * enemy_y + arr21 * (enemy_z - 50) + arr31) * zoom * sightheight * 1 - 20; float squareheight = camera_y2 - camera_y;//方框高度 Util.DllHelper.DrawSquare((int)(camera_x - squareheight / 4), (int)camera_y,(int) (squareheight / 2), (int)squareheight, Util.DllHelper.COLORYELLOW, Util.DllHelper.COLORRED,1);//绘制方框 Util.DllHelper.OptimizeSystem();//系统处理事件防止cup过多 Util.DllHelper.DrawLine((int)sightwidth,0, (int)camera_x, (int)camera_y,1,Util.DllHelper.COLORBLUE);//画直线 } private void reflushWindows()//刷新窗口 { Util.GameUtil.RECTClient rec = new Util.GameUtil.RECTClient() ; Util.GameUtil.LPPOINT point = new Util.GameUtil.LPPOINT(); Util.GameUtil.GetClientRect(windowshandle,out rec); Util.GameUtil.ClientToScreen(windowshandle, out point); formwidth = rec.Right-rec.Left; formheight = rec.Bottom-rec.Top ; Util.DllHelper.MoveWindows(dx11hwnd, point.x, point.y, (int)formwidth, (int)formheight); Util.DllHelper.SetWindowPos_Top(dx11hwnd); } public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { startIt(); } private void Form1_Load(object sender, EventArgs e) { intData(); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { // Util.DllHelper.SafetyQuit(); Environment.Exit(0); } }
测试图(占用cpu极少)

