赞
踩
.net实现游戏外挂,完整代码(原创)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
namespace 密传外挂
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Timer timer2;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCanel;
private System.Windows.Forms.TextBox txtCollimation;
private System.Windows.Forms.TextBox txtAttack;
private System.Windows.Forms.TextBox txtTime;
private System.Windows.Forms.TextBox txtMP;
private System.Windows.Forms.TextBox txtHP;
private string strCollimation; //瞄准键
private string strAttack; //攻击键
private string strHP; //补血键
private string strMP; //补蓝键
private bool whichKey; //瞄准和攻击的状态
private int count;
// 桌面工作区的尺寸
Size workingArea;
// Form 的初始位置和在左下角,右下角的位置
Point formLoc, ptLeftBottom, ptRightBottom;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
Rectangle rect = SystemInformation.WorkingArea;
workingArea = new Size(rect.Width, rect.Height);
ptLeftBottom = new Point(0, workingArea.Height - this.Height);
ptRightBottom = new Point(workingArea.Width - this.Width,workingArea.Height - this.Height);
count = 0;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.btnOK = new System.Windows.Forms.Button();
this.txtCollimation = new System.Windows.Forms.TextBox();
this.txtAttack = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.btnCanel = new System.Windows.Forms.Button();
this.txtTime = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.txtMP = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.txtHP = new System.Windows.Forms.TextBox();
this.timer2 = new System.Windows.Forms.Timer(this.components);
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(48, 160);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 0;
this.btnOK.Text = "确定";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// txtCollimation
//
this.txtCollimation.Location = new System.Drawing.Point(72, 24);
this.txtCollimation.Name = "txtCollimation";
this.txtCollimation.Size = new System.Drawing.Size(48, 21);
this.txtCollimation.TabIndex = 1;
this.txtCollimation.Text = "";
//
// txtAttack
//
this.txtAttack.Location = new System.Drawing.Point(72, 64);
this.txtAttack.Name = "txtAttack";
this.txtAttack.Size = new System.Drawing.Size(48, 21);
this.txtAttack.TabIndex = 2;
this.txtAttack.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 23);
this.label1.TabIndex = 3;
this.label1.Text = "瞄准";
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 23);
this.label2.TabIndex = 4;
this.label2.Text = "攻击";
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// btnCanel
//
this.btnCanel.Location = new System.Drawing.Point(208, 160);
this.btnCanel.Name = "btnCanel";
this.btnCanel.TabIndex = 5;
this.btnCanel.Text = "取消";
this.btnCanel.Click += new System.EventHandler(this.btnCanel_Click);
//
// txtTime
//
this.txtTime.Location = new System.Drawing.Point(32, 104);
this.txtTime.MaxLength = 4;
this.txtTime.Name = "txtTime";
this.txtTime.Size = new System.Drawing.Size(32, 21);
this.txtTime.TabIndex = 6;
this.txtTime.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 96);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(16, 16);
this.label3.TabIndex = 7;
this.label3.Text = "每";
//
// label4
//
this.label4.Location = new System.Drawing.Point(72, 96);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(80, 23);
this.label4.TabIndex = 8;
this.label4.Text = "秒,按下一次";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.txtAttack);
this.groupBox1.Controls.Add(this.txtTime);
this.groupBox1.Controls.Add(this.txtCollimation);
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(160, 136);
this.groupBox1.TabIndex = 9;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "攻击设定";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.txtMP);
this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.txtHP);
this.groupBox2.Location = new System.Drawing.Point(176, 8);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(136, 136);
this.groupBox2.TabIndex = 10;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "自动恢复";
//
// txtMP
//
this.txtMP.Location = new System.Drawing.Point(64, 80);
this.txtMP.Name = "txtMP";
this.txtMP.Size = new System.Drawing.Size(64, 21);
this.txtMP.TabIndex = 3;
this.txtMP.Text = "";
//
// label6
//
this.label6.Location = new System.Drawing.Point(16, 88);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(48, 23);
this.label6.TabIndex = 2;
this.label6.Text = "恢复蓝";
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 40);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(48, 23);
this.label5.TabIndex = 1;
this.label5.Text = "恢复血";
//
// txtHP
//
this.txtHP.Location = new System.Drawing.Point(64, 40);
this.txtHP.Name = "txtHP";
this.txtHP.Size = new System.Drawing.Size(64, 21);
this.txtHP.TabIndex = 0;
this.txtHP.Text = "";
//
// timer2
//
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(320, 189);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnCanel);
this.Controls.Add(this.btnOK);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "密传外挂 - 小新软件";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
//初始化设置
private void Init(){
this.timer1.Interval =Convert.ToInt32(Convert.ToDouble(this.txtTime.Text) * 1000);
this.whichKey = false;
strCollimation = this.txtCollimation.Text;
strAttack = this.txtAttack.Text;
strHP = this.txtHP.Text;
strMP = this.txtMP.Text;
}
private void btnOK_Click(object sender, System.EventArgs e){
Init();
IntPtr hParent = IntPtr.Zero;
IntPtr hNext=IntPtr.Zero;
string sClassName = "Tantra Launcher"; //窗口标题
hNext=FindWindowEx(hParent,hNext,IntPtr.Zero,sClassName);
if(hNext.ToInt32()>0){
SetForegroundWindow(hNext.ToInt32());//置顶显示
ShowWindow(hNext.ToInt32(),nCmdShow.SW_SHOWMINNOACTIVE); //显示窗口
//System.Windows.Forms.SendKeys.Send(strWindow);// "%{F4}" 是ALT + F4
this.timer1.Enabled = true;
this.timer2.Enabled = true;
}
else
MessageBox.Show("错误","未发现游戏,请先启动游戏后在打开外挂!",MessageBoxButtons.OK,MessageBoxIcon.Error);
formLoc = this.Location;
this.Location = ptRightBottom;
}
private void timer1_Tick(object sender, System.EventArgs e){
if(this.whichKey == false){
System.Windows.Forms.SendKeys.Send(strCollimation);// "%{F4}" 是ALT + F4
this.whichKey = true;
}
else{
System.Windows.Forms.SendKeys.Send(strAttack);
this.whichKey = false;
}
}
private void btnCanel_Click(object sender, System.EventArgs e){
this.timer1.Enabled = false;
this.timer2.Enabled = false;
}
[ DllImport ( "gdi32.dll" ) ]
private static extern bool BitBlt (
IntPtr hdcDest, // 目标设备的句柄
int nXDest, // 目标对象的左上角的X坐标
int nYDest, // 目标对象的左上角的X坐标
int nWidth, // 目标对象的矩形的宽度
int nHeight, // 目标对象的矩形的长度
IntPtr hdcSrc, // 源设备的句柄
int nXSrc, // 源对象的左上角的X坐标
int nYSrc, // 源对象的左上角的X坐标
int dwRop // 光栅的操作值
);
[ DllImport ( "gdi32.dll" ) ]
private static extern IntPtr CreateDC (
string lpszDriver, // 驱动名称
string lpszDevice, // 设备名称
string lpszOutput, // 无用,可以设定位"NULL"
IntPtr lpInitData // 任意的打印机数据
);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr FindWindowEx(IntPtr parent /*HWND*/,
IntPtr next /*HWND*/,
IntPtr sClassName,
string sWindowTitle);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern void SetForegroundWindow(int hwnd);
[DllImport("user32.dll")]
public static extern bool ShowWindow(int hWnd, nCmdShow nCmdShow);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
//SendMessage(Handle2, WM_GETTEXT, 1024, Integer(@Buf));
public enum nCmdShow:uint {
SW_FORCEMINIMIZE=0x0,
SW_HIDE=0x1,
SW_MAXIMIZE=0x2,
SW_MINIMIZE=0x3,
SW_RESTORE=0x4,
SW_SHOW=0x5,
SW_SHOWDEFAULT=0x6,
SW_SHOWMAXIMIZED=0x7,
SW_SHOWMINIMIZED=0x8,
SW_SHOWMINNOACTIVE=0x9,
SW_SHOWNA=0xA,
SW_SHOWNOACTIVATE=0xB,
SW_SHOWNORMAL=0xC,
WM_CLOSE=0x10,
}
private void timer2_Tick(object sender, System.EventArgs e){
// 创建显示器的DC
IntPtr hdlDisplay = CreateDC("DISPLAY", null, null, IntPtr.Zero);
// 从指定设备的句柄创建新的 Graphics 对象
Graphics gfxDisplay = Graphics.FromHdc(hdlDisplay);
// 创建只有一个象素大小的 Bitmap 对象
Bitmap bmp1 = new Bitmap(1, 1, gfxDisplay);
Bitmap bmp2 = new Bitmap(1, 1, gfxDisplay);
// 从指定 Image 对象创建新的 Graphics 对象
Graphics gfxBmp1 = Graphics.FromImage(bmp1);
Graphics gfxBmp2 = Graphics.FromImage(bmp2);
// 获得屏幕的句柄
IntPtr hdlScreen = gfxDisplay.GetHdc();
// 获得位图的句柄
IntPtr hdlBmp1 = gfxBmp1.GetHdc();
IntPtr hdlBmp2 = gfxBmp2.GetHdc();
// 把当前屏幕中鼠标指针所在位置的一个象素拷贝到位图中
BitBlt(hdlBmp1, 0, 0, 1, 1, hdlScreen, 97, 25, 13369376);
BitBlt(hdlBmp2, 0, 0, 1, 1, hdlScreen, 97, 20, 13369376);
// 释放屏幕句柄
gfxDisplay.ReleaseHdc(hdlScreen);
// 释放位图句柄
gfxBmp1.ReleaseHdc(hdlBmp1);
gfxBmp2.ReleaseHdc(hdlBmp2);
Color temp1 = bmp1.GetPixel(0, 0); // 获取像素的颜色
Color temp2 = bmp2.GetPixel(0, 0);
int beforeCount = this.count;
if((temp1.ToArgb().ToString("x").ToUpper() == "FFFFFFFF") && (temp2.ToArgb().ToString("x").ToUpper() == "FFFFFFFF"))
this.count ++;
if(beforeCount == this.count)
this.count = 0;
if((temp1.ToArgb().ToString("x").ToUpper() == "FFFFFFFF") &&(count == 2) &&(beforeCount != this.count)){
this.count = 0;
System.Windows.Forms.SendKeys.Send(strHP);
}
gfxDisplay.Dispose();
gfxBmp1.Dispose();
gfxBmp2.Dispose();
bmp1.Dispose(); // 释放 bmp 所使用的资源
bmp2.Dispose();
}
}
}
WindowsXP,2003下调试成功,密传的版本忘了,反正是公测时候的,职业是弓箭手.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。