Hi all,
I got a problem with my code to check a game's chat position and write text to the game when a command is written by someone on the chat. I haven't figured out yet how to make it send keys to the gamewindow when it's not focussed, and WriteProcessMem ory, but that's for a later issue.
This is my current code:
[code=vb]
Public Const PROCESS_ALL_ACC ESS As Long = &H1F0FFF
Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Public Declare Function ReadProcessMemo ry Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Byte, ByVal nSize As Integer, ByRef lpNumberOfBytes Written As Integer) As Integer
Public Declare Function WriteProcessMem ory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytes Written As Integer) As Integer
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As IntPtr) As Integer
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As IntPtr
Public Sub ReadChat(ByVal Command As String)
Dim hwnd As Integer
Dim hprocess As Integer
Dim readprocess
Dim chataddress As Integer
Dim votesneeded As String = txtvotesneeded. Text
If hwnd = FindWindow(vbNu llString, Game1) = True Then
chataddress = &H698726
ElseIf hwnd = FindWindow(vbNu llString, Game2) = True Then
chataddress = &H685381
Else
MsgBox("Please Startup the game first before clicking the Start button", MsgBoxStyle.Cri tical, "Error!")
End If
On Error Resume Next
MsgBox("Error #17 occured. Please ask for help at support forum.", MsgBoxStyle.Cri tical, "Error!")
If hwnd >= 0 Then
hprocess = OpenProcess(PRO CESS_ALL_ACCESS , False, hwnd)
readprocess = ReadProcessMemo ry(hprocess, ChatAddress, 78, 78, vbNullString)
CloseHandle(hpr ocess)
End If
If readprocess = Command Then
SendKeys.Send(" {T}")
Wait(100)
SendKeys.Send(" There are " & votesneeded & " more votes needed to skip map.")
Wait(100)
SendKeys.Send(" {ENTER}")
End If
End Sub
[/code]
The game consists of 2 different versions, that's why I want it to change the chataddress to suit each version.
I'm not sure if I done all this code the right way. The only error it gave me during runtime was something with "readproces s". A conversion from type String to type Double failed.
I hope someone can help me get this code right and help me taking any errors out which could prevent it from working perfect.
Thanks in advance !
Evolution445
I got a problem with my code to check a game's chat position and write text to the game when a command is written by someone on the chat. I haven't figured out yet how to make it send keys to the gamewindow when it's not focussed, and WriteProcessMem ory, but that's for a later issue.
This is my current code:
[code=vb]
Public Const PROCESS_ALL_ACC ESS As Long = &H1F0FFF
Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Public Declare Function ReadProcessMemo ry Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Byte, ByVal nSize As Integer, ByRef lpNumberOfBytes Written As Integer) As Integer
Public Declare Function WriteProcessMem ory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytes Written As Integer) As Integer
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As IntPtr) As Integer
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As IntPtr
Public Sub ReadChat(ByVal Command As String)
Dim hwnd As Integer
Dim hprocess As Integer
Dim readprocess
Dim chataddress As Integer
Dim votesneeded As String = txtvotesneeded. Text
If hwnd = FindWindow(vbNu llString, Game1) = True Then
chataddress = &H698726
ElseIf hwnd = FindWindow(vbNu llString, Game2) = True Then
chataddress = &H685381
Else
MsgBox("Please Startup the game first before clicking the Start button", MsgBoxStyle.Cri tical, "Error!")
End If
On Error Resume Next
MsgBox("Error #17 occured. Please ask for help at support forum.", MsgBoxStyle.Cri tical, "Error!")
If hwnd >= 0 Then
hprocess = OpenProcess(PRO CESS_ALL_ACCESS , False, hwnd)
readprocess = ReadProcessMemo ry(hprocess, ChatAddress, 78, 78, vbNullString)
CloseHandle(hpr ocess)
End If
If readprocess = Command Then
SendKeys.Send(" {T}")
Wait(100)
SendKeys.Send(" There are " & votesneeded & " more votes needed to skip map.")
Wait(100)
SendKeys.Send(" {ENTER}")
End If
End Sub
[/code]
The game consists of 2 different versions, that's why I want it to change the chataddress to suit each version.
I'm not sure if I done all this code the right way. The only error it gave me during runtime was something with "readproces s". A conversion from type String to type Double failed.
I hope someone can help me get this code right and help me taking any errors out which could prevent it from working perfect.
Thanks in advance !
Evolution445
Comment