版上的大大們都是使用VB6在撰寫
小弟是使用VB2008,所以小弟自己動手修改一些VB2008跟VB6
語法OR(caption把它換成textbox之類的)的差異
目前遇到兩個問題
1.雙視窗可以使用 但是他會把我的視窗標題整個消掉
而不是變成像是原碼寫的 變成 Element Client&i
2.讀取腳色資料沒法讀取
附上小弟的原碼
- Public Class Form1
- '====================================================================================API Define
- Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
- Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer
- Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
- Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
- Private Declare Function ReadProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Long, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
- Dim pid As Long
- Const PW_Base = &H95BAA4
- Dim W2I_DYNAMIC_BASE_ADDR As Long
- Dim W2I_ROLE_BASE_ADDR As Long
- Const PROCESS_ALL_ACCESS = &H1F0FFF
- Dim hp As Long, mp As Long, maxhp As Long, maxmp As Long, genki As Long
- Dim name_temp As Long
- Dim pplname As String
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Dim proc As Long
- TextBox1.Text = "Element Client"
- proc = FindWindow(vbNullString, TextBox1.Text) 'Text1.text = 完美的視窗標題"Element Client"
- If proc > 0 Then '找到"Element Client"的完美視窗
- GetWindowThreadProcessId(proc, pid) '取得 process ID (pid)
- Label1.Text = "遊戲啟動! pid = " & pid
- Else '沒找到"Element Client"
- Label1.Text = "遊戲未啟動"
- End If
- End Sub
- '====================================================================================雙視窗
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim proc As IntPtr
- Dim i As Integer
- proc = FindWindow(vbNullString, TextBox1.Text)
- If proc.Equals(IntPtr.Zero) Then '找到完美視窗"Element Client"
- MsgBox("請先執行完美世界主程式。")
- Else
- i = 2
- Do While FindWindow(vbNullString, TextBox1.Text & i) <> 0 '找不重複的視窗標題"Element Client" + 數字(從2開始)
- i = i + 1
- Loop
- TextBox1.Text &= i
- 'Call SetWindowText(proc, TextBox1.Text) '修改視窗標題
- SetWindowText(proc, TextBox1.Text)
- MsgBox("修改完成,請開啟另一個完美世界主程式。")
- End If
- End Sub
- '====================================================================================連線上角色
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Dim hProcess As Long
- hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid) '連上完美遊戲
- If hProcess = 0 Then '無法連上完美遊戲
- MsgBox("not found")
- Exit Sub '離開
- End If
- ReadProcessMemory(hProcess, PW_Base, W2I_DYNAMIC_BASE_ADDR, 4, 0&) '一級基址
- ReadProcessMemory(hProcess, W2I_DYNAMIC_BASE_ADDR + &H20, W2I_ROLE_BASE_ADDR, 4, 0&) '人物基址
- ReadProcessMemory(hProcess, W2I_ROLE_BASE_ADDR + &H5F0, name_temp, 4, 0&) '得到角色名稱
- ReadProcessMemory(hProcess, name_temp, pplname, 32, 0&)
- Me.Text = pplname '設定外掛的視窗標題為角色名稱
- Timer1.Enabled = True '打開Timer, 以便每隔1秒讀取人物HP, MP,元氣
- CloseHandle(hProcess)
- End Sub
- Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
- pid = 0
- lbHP.Text = "0 / 0" '清空HP
- lbMP.Text = "0 / 0" '清空MP
- lbGenki.Text = "0" '清空元氣
- Timer1.Enabled = False '取消Timer
- End Sub
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- Dim hProcess As Long
- ReadProcessMemory(hProcess, W2I_ROLE_BASE_ADDR + &H464, hp, 4, 0&) 'HP
- ReadProcessMemory(hProcess, W2I_ROLE_BASE_ADDR + &H468, mp, 4, 0&) 'MP
- ReadProcessMemory(hProcess, W2I_ROLE_BASE_ADDR + &H494, maxhp, 4, 0&) 'Max HP
- ReadProcessMemory(hProcess, W2I_ROLE_BASE_ADDR + &H498, maxmp, 4, 0&) 'MAx MP
- ReadProcessMemory(hProcess, W2I_ROLE_BASE_ADDR + &H478, genki, 4, 0&) '元氣
- lbHP.text = hp & " / " & maxhp '顯示現在HP / Max HP
- lbMP.text = mp & " / " & maxmp '顯示現在MP / Max MP
- lbGenki.text = genki '顯示現在元氣值
- End Sub
- End Class
複製代碼 |