InPowerS.Net

 找回密碼
 註冊
搜索
查看: 2116|回復: 0

[轉貼]VB 從零開始編外掛(四)

[複製鏈接]
發表於 2008-12-25 21:59:53 | 顯示全部樓層 |閱讀模式
--------------------------------------------------------------------------------------------------------------------------------------------------------
前邊談了類比鍵盤,下面說說類比滑鼠。
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要VB API函數:
mouse_event                             ←類比一次滑鼠事件
--------------------------------------------------------------------------------------------------------------------------------------------------------
相關API聲明:
mouse_event

Private Declare Sub mouse_event Lib "user32"  ( ByVal dwFlags As Long, ByVal dx As Long,  ByVal dy As Long,  ByVal cButtons As Long, ByVal dwExtraInfo As Long  )
--------------------------------------------------------------------------------------------------------------------------------------------------------
定義變數:
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
--------------------------------------------------------------------------------------------------------------------------------------------------------
MOUSEEVENTF_LEFTDOWN'滑鼠左鍵按下
MOUSEEVENTF_LEFTUP'滑鼠鬆開
MOUSEEVENTF_RIGHTDOWN '滑鼠右鍵按下
MOUSEEVENTF_RIGHTUP'滑鼠右鍵鬆開
--------------------------------------------------------------------------------------------------------------------------------------------------------
代碼:
Private Declare Sub mouse_event Lib "user32"  ( ByVal dwFlags As Long, ByVal dx As Long,  ByVal dy As Long,  ByVal cButtons As Long, ByVal dwExtraInfo As Long  )
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
'這裡是 滑鼠左鍵按下 和鬆開兩個事件的組合即一次按一下
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
'類比滑鼠按右鍵事件
mouse_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
'兩次連續的滑鼠左鍵按一下事件 構成一次滑鼠按兩下事件
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
--------------------------------------------------------------------------------------------------------------------------------------------------------
應用實戰
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要VB API函數:
FindWindow
GetWindowThreadProcessId
OpenProcess
ReadProcessMemory
CloseHandle
--------------------------------------------------------------------------------------------------------------------------------------------------------
相關API聲明:
FindWindow

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
GetWindowThreadProcessId

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long)
As Long
OpenProcess

Private Declare Function OpenProcess Lib  "kernel32" (ByVal  dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal  dwProcessId As Long) As Long
ReadProcessMemory

Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
CloseHandle

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
GetCurrentProcess

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要的控制項:Label、Timer(interval不為空)、Text
--------------------------------------------------------------------------------------------------------------------------------------------------------
定義函數:
Dim SetHp As Integer        ' 定義設定的體力值
Dim SetMp As Integer         ' 定義設定的魔法值
Dim NowHp As Long           ' 定義目前的體力值
Dim NowMp As Long           ' 定義目前的魔法值
Dim MaxHp As Long           ' 定義角色的最高體力值
Dim MaxMp As Long          ' 定義角色的最高魔法值
Dim DiZhi As Long              '定義記憶體位址函數
Dim hwnd As Long              ' 儲存 FindWindow 函數返回的控制碼
--------------------------------------------------------------------------------------------------------------------------------------------------------
代碼:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long)
As Long
Private Declare Function OpenProcess Lib  "kernel32" (ByVal  dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal  dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Dim SetHp As Integer        ' 定義設定的體力值
Dim SetMp As Integer         ' 定義設定的魔法值
Dim NowHp As Long           ' 定義目前的體力值
Dim NowMp As Long           ' 定義目前的魔法值
Dim MaxHp As Long           ' 定義角色的最高體力值
Dim MaxMp As Long          ' 定義角色的最高魔法值
Dim DiZhi As Long              '定義記憶體位址函數
Private Function ncnr(lpADDress As Long) As Integer
    ' 聲明一些需要的變數
    Dim hwnd As Long        ' 儲存 FindWindow 函數返回的控制碼
    Dim pid As Long         ' 儲存進程識別字( Process Id )
    Dim pHandle As Long     ' 儲存進程控制碼
    hwnd = FindWindow(vbNullString, "封神榜•網路版")
    ' 取得進程識別字
    GetWindowThreadProcessId hwnd, pid
    ' 使用進程識別字取得進程控制碼
    pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
    ' 在記憶體位址中讀取資料
    ReadProcessMemory pHandle, lpADDress, ByVal VarPtr(ncnr), 4, 0&
    ' 關閉進程控制碼
    CloseHandle hProcess
End Function
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const SYNCHRONIZE = &H100000
Const SPECIFIC_RIGHTS_ALL = &HFFFF
Const STANDARD_RIGHTS_ALL = &H1F0000
Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
Const PROCESS_VM_OPERATION = &H8&
Const PROCESS_VM_READ = &H10&
Const PROCESS_VM_WRITE = &H20&

Private Sub Form_Load()
  ' 體力:07F68F3 這裡替換你所搜索到的位址  魔法:07F6860 同前
    DiZhi = &H07F68F3
    Timer1.Enabled = True
    Timer2.Enabled = False
    Timer3.Enabled = False
End Sub
Private Sub Timer1_Timer()
    Dim hwnd As Long
    hwnd = FindWindow(vbNullString, "封神榜•網路版")
   
    If hwnd = 0 Then
        Label12.Caption = "遊戲未載入"
        Timer1.Enabled = True
        Timer2.Enabled = False
        Timer3.Enabled = False
        Exit Sub
    End If
    Label12.Caption = "遊戲已載入"
    SetHp = Text1.Text          ' 獲取設定的體力值
    SetMp = Text2.Text          ' 獲取設定的魔法值
    NowHp = ncnr(DiZhi)         ' 獲取當前的體力值
    NowMp = ncnr(DiZhi + 12)    ' 獲取當前的魔法值
    MaxHp = ncnr(DiZhi + 4)     ' 獲取角色的最高體力值
    MaxMp = ncnr(DiZhi + 16)    ' 獲取角色的最高魔法值
    Label3.Caption = Str(NowHp) + "/" + Str(MaxHp)      ' 顯示角色體力值狀態
    Label4.Caption = Str(NowMp) + "/" + Str(MaxMp)      ' 顯示角色魔法值狀態
    If Check1.Value Then
        Timer2.Enabled = True
    Else
        Timer2.Enabled = False
    End If
    If Check2.Value Then
        Timer3.Enabled = True
    Else
        Timer3.Enabled = False
    End If
End Sub
Private Sub Timer2_Timer()
    ' 體力值小於設定值按下數字鍵1
    If (NowHp) < SetHp Then
        SendKeys "1"
    End If
End Sub
Private Sub Timer3_Timer()
    ' 魔法值小於設定值按下數字鍵2
    If (NowMp) < SetMp Then
        SendKeys "2"
    End If
End Sub
VB 從零開始編外掛(四)
原作者或上傳者:glasser  出處:CSDN  環境:VB.NET  點擊數:1021   
--------------------------------------------------------------------------------------------------------------------------------------------------------
前邊談了類比鍵盤,下面說說類比滑鼠。
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要VB API函數:
mouse_event                             ←類比一次滑鼠事件
--------------------------------------------------------------------------------------------------------------------------------------------------------
相關API聲明:
mouse_event

Private Declare Sub mouse_event Lib "user32"  ( ByVal dwFlags As Long, ByVal dx As Long,  ByVal dy As Long,  ByVal cButtons As Long, ByVal dwExtraInfo As Long  )
--------------------------------------------------------------------------------------------------------------------------------------------------------
定義變數:
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
--------------------------------------------------------------------------------------------------------------------------------------------------------
MOUSEEVENTF_LEFTDOWN'滑鼠左鍵按下
MOUSEEVENTF_LEFTUP'滑鼠鬆開
MOUSEEVENTF_RIGHTDOWN '滑鼠右鍵按下
MOUSEEVENTF_RIGHTUP'滑鼠右鍵鬆開
--------------------------------------------------------------------------------------------------------------------------------------------------------
代碼:
Private Declare Sub mouse_event Lib "user32"  ( ByVal dwFlags As Long, ByVal dx As Long,  ByVal dy As Long,  ByVal cButtons As Long, ByVal dwExtraInfo As Long  )
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
'這裡是 滑鼠左鍵按下 和鬆開兩個事件的組合即一次按一下
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
'類比滑鼠按右鍵事件
mouse_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
'兩次連續的滑鼠左鍵按一下事件 構成一次滑鼠按兩下事件
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
--------------------------------------------------------------------------------------------------------------------------------------------------------
應用實戰
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要VB API函數:
FindWindow
GetWindowThreadProcessId
OpenProcess
ReadProcessMemory
CloseHandle
--------------------------------------------------------------------------------------------------------------------------------------------------------
相關API聲明:
FindWindow

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
GetWindowThreadProcessId

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long)
As Long
OpenProcess

Private Declare Function OpenProcess Lib  "kernel32" (ByVal  dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal  dwProcessId As Long) As Long
ReadProcessMemory

Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
CloseHandle

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
GetCurrentProcess

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要的控制項:Label、Timer(interval不為空)、Text
--------------------------------------------------------------------------------------------------------------------------------------------------------
定義函數:
Dim SetHp As Integer        ' 定義設定的體力值
Dim SetMp As Integer         ' 定義設定的魔法值
Dim NowHp As Long           ' 定義目前的體力值
Dim NowMp As Long           ' 定義目前的魔法值
Dim MaxHp As Long           ' 定義角色的最高體力值
Dim MaxMp As Long          ' 定義角色的最高魔法值
Dim DiZhi As Long              '定義記憶體位址函數
Dim hwnd As Long              ' 儲存 FindWindow 函數返回的控制碼
--------------------------------------------------------------------------------------------------------------------------------------------------------
代碼:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long)
As Long
Private Declare Function OpenProcess Lib  "kernel32" (ByVal  dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal  dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Dim SetHp As Integer        ' 定義設定的體力值
Dim SetMp As Integer         ' 定義設定的魔法值
Dim NowHp As Long           ' 定義目前的體力值
Dim NowMp As Long           ' 定義目前的魔法值
Dim MaxHp As Long           ' 定義角色的最高體力值
Dim MaxMp As Long          ' 定義角色的最高魔法值
Dim DiZhi As Long              '定義記憶體位址函數
Private Function ncnr(lpADDress As Long) As Integer
    ' 聲明一些需要的變數
    Dim hwnd As Long        ' 儲存 FindWindow 函數返回的控制碼
    Dim pid As Long         ' 儲存進程識別字( Process Id )
    Dim pHandle As Long     ' 儲存進程控制碼
    hwnd = FindWindow(vbNullString, "封神榜&#8226;網路版")
    ' 取得進程識別字
    GetWindowThreadProcessId hwnd, pid
    ' 使用進程識別字取得進程控制碼
    pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
    ' 在記憶體位址中讀取資料
    ReadProcessMemory pHandle, lpADDress, ByVal VarPtr(ncnr), 4, 0&
    ' 關閉進程控制碼
    CloseHandle hProcess
End Function
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const SYNCHRONIZE = &H100000
Const SPECIFIC_RIGHTS_ALL = &HFFFF
Const STANDARD_RIGHTS_ALL = &H1F0000
Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
Const PROCESS_VM_OPERATION = &H8&
Const PROCESS_VM_READ = &H10&
Const PROCESS_VM_WRITE = &H20&

Private Sub Form_Load()
  ' 體力:07F68F3 這裡替換你所搜索到的位址  魔法:07F6860 同前
    DiZhi = &H07F68F3
    Timer1.Enabled = True
    Timer2.Enabled = False
    Timer3.Enabled = False
End Sub
Private Sub Timer1_Timer()
    Dim hwnd As Long
    hwnd = FindWindow(vbNullString, "封神榜&#8226;網路版")
   
    If hwnd = 0 Then
        Label12.Caption = "遊戲未載入"
        Timer1.Enabled = True
        Timer2.Enabled = False
        Timer3.Enabled = False
        Exit Sub
    End If
    Label12.Caption = "遊戲已載入"
    SetHp = Text1.Text          ' 獲取設定的體力值
    SetMp = Text2.Text          ' 獲取設定的魔法值
    NowHp = ncnr(DiZhi)         ' 獲取當前的體力值
    NowMp = ncnr(DiZhi + 12)    ' 獲取當前的魔法值
    MaxHp = ncnr(DiZhi + 4)     ' 獲取角色的最高體力值
    MaxMp = ncnr(DiZhi + 16)    ' 獲取角色的最高魔法值
    Label3.Caption = Str(NowHp) + "/" + Str(MaxHp)      ' 顯示角色體力值狀態
    Label4.Caption = Str(NowMp) + "/" + Str(MaxMp)      ' 顯示角色魔法值狀態
    If Check1.Value Then
        Timer2.Enabled = True
    Else
        Timer2.Enabled = False
    End If
    If Check2.Value Then
        Timer3.Enabled = True
    Else
        Timer3.Enabled = False
    End If
End Sub
Private Sub Timer2_Timer()
    ' 體力值小於設定值按下數字鍵1
    If (NowHp) < SetHp Then
        SendKeys "1"
    End If
End Sub
Private Sub Timer3_Timer()
    ' 魔法值小於設定值按下數字鍵2
    If (NowMp) < SetMp Then
        SendKeys "2"
    End If
End Sub
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

小黑屋|Archiver|手機版|InPowerS.Net

GMT+8, 2018-8-18 07:12

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回復 返回頂部 返回列表