Recently started to play the Secret network game by a friend introduction
Upgrade upgrade, suddenly feel too fee keyboard, so I wrote a program with C #, want to replace my operation, I go to play monsters, their own upgrade
With this thing up a lot of levels, now put the source code out, and everyone to share, welcome criticism, thank you.
The program is divided into two parts, one part is the class library, the other is the application
The idea is to find the main window handle of the game process, and then send the game key message (analog button).
Xdf. Gameplugincommon Class Library Project
API.cs files, defining some common API functions and constants
Using System;
Using System.IO;
Using System.Threading;
Using System.Diagnostics;
Using System.Runtime.InteropServices;
Namespace XDF. Gameplugincommon
{
<summary>
Summary description of the 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);
This is primarily used to place the window at the Front (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= "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;
}
}
}
Project (Application)
Xdf. Tantraplugin
ControlItem.cs
Using System;
Using System.IO;
Using System.Xml.Serialization;
Namespace XDF. Tantraplugin
{
<summary>
Summary description of the 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>
Summary description of the 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)
{
BOOL result = FALSE;
Try
{
FileStream fs = new FileStream (file,filemode.create,fileaccess.write);
XmlSerializer xsl = new XmlSerializer (this. GetType ());
Xsl. Serialize (Fs,this);
Fs. Close ();
result = true;
}
Catch
{
result = false;
}
return result;
}
public static Tantraconfig LoadFromFile (string file)
{
Tantraconfig config = null;
Try
{
FileStream fs = new FileStream (file,filemode.open,fileaccess.read);
XmlSerializer xsl = new XmlSerializer (typeof (Tantraconfig));
Config = (tantraconfig) xsl. Deserialize (FS);
Fs. Close ();
}
Catch
{
}
return config;
}
}
}
Frmmain.cs
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Using System.Threading;
Using XDF. Gameplugincommon;
Namespace XDF. Tantraplugin
{
<summary>
Summary description of the Form1.
</summary>
public class Frmmain:System.Windows.Forms.Form
{
Private System.Windows.Forms.Button Btnsetup;
Private System.Windows.Forms.Timer Timermain;
Private System.Windows.Forms.Button btnstart;
Private System.ComponentModel.IContainer components;
Public Frmmain ()
{
//
Required for Windows Forms Designer support
//
InitializeComponent ();
<summary>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}
Code generated #region the Windows forms Designer
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
this.components = new System.ComponentModel.Container ();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (Frmmain));
This.btnstart = new System.Windows.Forms.Button ();
This.btnsetup = new System.Windows.Forms.Button ();
This.timermain = new System.Windows.Forms.Timer (this.components);
This. SuspendLayout ();
//
Btnstart
//
This.btnStart.Location = new System.Drawing.Point (8, 16);
This.btnStart.Name = "Btnstart";
This.btnStart.Size = new System.Drawing.Size (65, 22);
This.btnStart.TabIndex = 0;
This.btnStart.Text = "Start (&s)";
This.btnStart.Click + = new System.EventHandler (This.btnstart_click);
//
Btnsetup
//
This.btnSetup.Location = new System.Drawing.Point (152, 16);
This.btnSetup.Name = "Btnsetup";
This.btnSetup.Size = new System.Drawing.Size (65, 22);
This.btnSetup.TabIndex = 1;
This.btnSetup.Text = "Set (&c)";
This.btnSetup.Click + = new System.EventHandler (This.btnsetup_click);
//
Frmmain
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (226, 55);
This. Controls.Add (This.btnsetup);
This. Controls.Add (This.btnstart);
This. FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
This. Icon = ((System.Drawing.Icon) (resources). GetObject ("$this. Icon "));
This. MaximizeBox = false;
This. MinimizeBox = false;
This. Name = "Frmmain";
This. StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
This. Text = "Tantra PlugIn beta1";
This. ResumeLayout (FALSE);
}
#endregion
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main ()
{
Application.Run (New Frmmain ());
}
Controlitem Item_f = new Controlitem ();
Item_f.delaytime = 500;
Item_f.keychar = ' F ';
Item_f.name = "Pick up playing after the monster fell off the object";
Items. ADD (Item_f);
Controlitem item_f2 = new Controlitem ();
Item_f2. Delaytime = 500;
Item_f2. Keychar = ' F ';
Item_f2. Name = "Pick up playing after the monster fell off the gold";
Items. ADD (ITEM_F2);
Controlitem Item_blood = new Controlitem ();
Item_blood. Delaytime = 1000;
Item_blood. Keychar = ' 1 ';
Item_blood. Name = "Automatic increase of physical ability";
Config. Bloodcontrols.add (Item_blood);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.