C# 游戏外挂实现核心代码

论坛 期权论坛 脚本     
niminba   2021-5-23 02:55   808   0
最近经朋友介绍开始玩 密传 网络游戏
升级升级,突然觉得太费键盘,于是自己用C#写了一个程序,想代替我的操作,自己去打怪物,自己升级
用这个东西升了好多级了,现在把源码贴出来,和大家共享,欢迎大家批评指正,感激不尽。
程序大概分成两个部分,一个部分是类库,一个是应用程序
大概的思路就是找到游戏进程的主窗口句柄,然后发送游戏按键消息(模拟按键)。


XDF.GamePlugInCommon 类库项目

//API.cs 文件,定义一些常用API函数及常量

using System;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace XDF.GamePlugInCommon
{
/// <summary>
/// API 的摘要说明。
/// </summary>
public sealed class API
{
public static int WM_KEYDOWN = 0x0100;
public static int WM_KEYUP = 0x0101;
public static int WM_SYSKEYDOWN = 0x0104;
public static int WM_SYSKEYUP = 0x0105;

public static int WM_MOUSEMOVE = 0x0200;
public static int WM_LBUTTONDOWN = 0x0201;
public static int WM_LBUTTONUP = 0x0202;
public static int WM_LBUTTONDBLCLK = 0x0203;
public static int WM_RBUTTONDOWN = 0x0204;
public static int WM_RBUTTONUP = 0x0205;
public static int WM_RBUTTONDBLCLK = 0x0206;
public static int WM_USER = 0x0400;

public static int MK_LBUTTON = 0x0001;
public static int MK_RBUTTON = 0x0002;
public static int MK_SHIFT = 0x0004;
public static int MK_CONTROL = 0x0008;
public static int MK_MBUTTON = 0x0010;

public static int MK_XBUTTON1 = 0x0020;
public static int MK_XBUTTON2 = 0x0040;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd,int Msg,int wParam,int lParam);

//此处主要用来让窗口置于最前(SetWindowPos(this.Handle,-1,0,0,0,0,0x4000|0x0001|0x0002);)
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd,
int hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
int uFlags
);

/// <summary>
/// 窗口置前
/// </summary>
/// <param name="hWnd"></param>
public static void SetWindowPos(IntPtr hWnd)
{
SetWindowPos(hWnd,-1,0,0,0,0,0x4000|0x0001|0x0002);
}

/// <summary>
///
/// </summary>
/// <param name="processName"></param>
/// <returns></returns>
public static Process GetGameProcess(string processName)
{
Process pro = null;
Process[] pros = Process.GetProcessesByName(processName);
if(pros.Length > 0)
{
pro = pros[0];
}
return pro;
}
}
}


项目(应用程序)
XDF.TantraPlugIn
//ControlItem.cs
using System;
using System.IO;
using System.Xml.Serialization;

namespace XDF.TantraPlugIn
{
/// <summary>
/// ControlItem 的摘要说明。
/// </summary>
[Serializable]
public sealed class ControlItem
{
private string m_Name = "";
public string Name
{
get
{
return this.m_Name;
}
set
{
this.m_Name = value;
}
}
private char m_KeyChar = 'a';
public char KeyChar
{
get
{
return this.m_KeyChar;
}
set
{
this.m_KeyChar = value;
}
}
private int m_DelayTime = 100;
public int DelayTime
{
get
{
return this.m_DelayTime;
}
set
{
this.m_DelayTime = value;
}
}
public ControlItem()
{

}
}
[Serializable]
public sealed class ControlItemCollection : System.Collections.CollectionBase
{
public ControlItem this[int index]
{
get
{
return (ControlItem)List[index];
}
set
{
List[index] = value;
}
}
public ControlItemCollection()
{
}
public int Add(ControlItem item)
{
return List.Add(item);
}
public void Remove(ControlItem item)
{
List.Remove(item);
}
}
}

//TantraConfig.cs
using System;
using System.IO;
using System.Xml.Serialization;

namespace XDF.TantraPlugIn
{
/// <summary>
/// TantraConfig 的摘要说明。
/// </summary>
[Serializable]
public class TantraConfig
{
private ControlItemCollection m_KillControls = new ControlItemCollection();
public ControlItemCollection KillControls
{
get
{
return this.m_KillControls;
}
set
{
this.m_KillControls = value;
}
}
private ControlItemCollection m_BloodControls = new ControlItemCollection();
public ControlItemCollection BloodControls
{
get
{
return this.m_BloodControls;
}
set
{
this.m_BloodControls = value;
}
}

private int m_BloodRate = 25;

public int BloodRate
{
get
{
return this.m_BloodRate;
}
set
{
this.m_BloodRate = value;
}
}

private string m_ProcessName = "HTLauncher";

public string ProcessName
{
get
{
return this.m_ProcessName;
}
set
{
this.m_ProcessName = value;
}
}

public TantraConfig()
{

}

public bool Save(string file)
{
boolA%MA$A}Q A95 "?}Q A9r&^B*}5]5]Q舀A9}M}QQQMхQ }QMхM}Q}M}QQ Ё}MЁ}Q - A$M5}5]A$]5}-e=]8 Q%}Q - t-QM}Q - t}Q IЁ}Q A$M5}5]A$]5}-e=]8 Q%}Q t-QM}Q t]A5]A5A$]5}-e=]8Q]AQ%QMQ5 } Ё Mэf*"G/[2 j7Q 輽a51M輽a51M- %9'.rR9-- % %9R'kjn9-- % %96&O3&:'j&N9-- % %96&O3&:'jG9-- %- %9*{**9-- % I IA9!Q1A9Q >G:j.RncjN73f"G3ror'
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP