ExclamationAutoit to VB 2010

Posts 1–15 of 33 · Page 1 of 3
Autoit to VB 2010
Autoit:
Code:
While 1 ; Main loop
  WinWaitActive("GTA:SA:MP")
  $pidm = WinGetProcess("GTA:SA:MP")
  $infom = _MemoryOpen($pidm)
  $code = _MemoryRead(0xC717F0, $infom, 'char[4]')
  $code = Int($code)
  if StringLen($code) = 4 Then
    Send('t/notafk ' & $code & '{ENTER}')
  EndIf
  _MemoryClose($infom)
  sleep(30000)
WEnd
Vb 2010:
Code:
Dim pidm
        Dim code
        pidm = Process.GetProcessesByName("GTA:SA:MP")
        code = ReadMemory(&HC717F0, 4)
        If Len(code) = 4 Then
            MsgBox(code)
        Else
            MsgBox("FAIL:" & code)
        End If

VB dont work
pidm = Process.GetProcessesByName("GTA:SA:MP")

check the task manager (Ctrl+Alt+Delete) for the process name. I think it's more like "gta4" or something similar.

edit: Also you should declare the data type of your variables..
I think the msgbox will say "System.Byte()" instead of the actual data. Use BitConverter.ToUInt32() or similar, to convert the byte array to some data type. ? maybe not.

Code:
        Dim pidm As System.Diagnostics.Process
        Dim code() As Byte 
       
        pidm = Process.GetProcessesByName("GTA:SA:MP") '' TODO: correct process name? Maybe define as constant later.
        code = ReadMemory(&HC717F0, 4)
        '' If ReadMemory returns "Nothing" then .Length will cause an error: who's memory library are you using.
        If code.Length = 4 Then
            MsgBox("Value Read: " & BitConverter.ToUint32(code,0).ToString())
        Else
            MsgBox("FAIL: " & BitConverter.ToUInt32(code,0).ToString()) '' Unable to ReadProcessMemory.
        End If
Wow, thank you I test it!
yep, no problem. Make post after you test. So other people can know : ) Please & Thanks.
error

//Edit: I failed! haha, I forgot () -.-
attachment take too long for approval -- for images --> upload to public server, like
t i n y p i c . c o m

and post the url that is like [img ] ******** [/img]

t i n y p i c . c o m is easy.
Lines:
Code:
MsgBox("Value Read: " & BitConverter.ToUint32(code,0).ToString())
MsgBox("FAIL: " & BitConverter.ToUInt32(code,0).ToString()) '' Unable to ReadProcessMemory
Error: ArgumentNullException
Because the MemoryRead failed. Your code looks incomplete. You don't tell the Read() function which process to read from. :/

pidm is never used.

It depends which (who's) memory library you're using. Does it have an Attach() method, or do you pass in the processID on every read, or what.. ?

---------- Post added at 10:17 PM ---------- Previous post was at 10:14 PM ----------

Post the code for the ReadMemory() Function.
Original: tamcore.eu/anti-afk-bot-fur-sa-mp/
those are .au3 autoit scripts. Your vb ReadMemory function is the one I'm talking about.

ReadMemory() is not a vb.net built in function. How do you have it in your code? Are you using someone else's library or what?
Which Memory Function must I use?

My Function:
Code:
Module Memory
    Public Const PROCESS_VM_READ = &H10
    Public Const PROCESS_VM_WRITE = (&H20)
    Public Const PROCESS_VM_OPERATION = (&H8)
    Public Const PROCESS_QUERY_INFORMATION = (&H400)
    Public Const PROCESS_READ_WRITE_QUERY = PROCESS_VM_READ + PROCESS_VM_WRITE + PROCESS_VM_OPERATION + PROCESS_QUERY_INFORMATION
    Public Const PROCESS_ALL_ACCESS = &H1F0FFF
    Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Int32, ByRef lpBuffer As Int32, ByVal nSize As Int32, ByVal lpNumberOfBytesWritten As Int32) As Long
    Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Int32, ByRef lpBuffer As Byte(), ByVal nSize As Int32, ByVal lpNumberOfBytesWritten As Int32) As Long
    Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Int32, ByVal lpBuffer() As Byte, ByVal nSize As Int32, ByVal lpNumberOfBytesWritten As Int32) As Long
    Public Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As UInteger, ByVal bInheritHandle As Integer, ByVal dwProcessId As UInteger) As IntPtr
    Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal hHandle As IntPtr) As Boolean
    Public Function Game_Hwnd() As Int32
        Dim i As Int32 : Dim foundit As Boolean = False
        For Each p As Process In Process.GetProcessesByName("Halo2") ' Replace that with the games window text
            i = p.Id
            foundit = True : Exit For
        Next
        If foundit = True Then
            Return i
        Else
            MsgBox("Couldn't find Game")
            Return 0
        End If
    End Function
#Region "Memory reading/Writing"
    Public Sub WriteMemory(ByVal Address As Integer, ByVal Value As Integer, ByVal Size As Integer)
        Try
            Dim GameReadWrite As Integer
            Dim PID As Integer = Game_Hwnd()
            GameReadWrite = OpenProcess(PROCESS_READ_WRITE_QUERY, False, PID)

            Dim bytArray() As Byte
            bytArray = BitConverter.GetBytes(Value)
            WriteProcessMemory(GameReadWrite, Address, bytArray, Size, 0)

            CloseHandle(GameReadWrite)
        Catch Ex As Exception
            'ShowError(Ex)
        End Try
    End Sub
    Public Sub WriteMemory(ByVal Address As Integer, ByVal Value() As Byte)
        Try
            Dim GameReadWrite As Integer
            Dim PID As Integer = Game_Hwnd()
            GameReadWrite = OpenProcess(PROCESS_READ_WRITE_QUERY, False, PID)

            WriteProcessMemory(GameReadWrite, Address, Value, Value.Length, 0)

            CloseHandle(GameReadWrite)
        Catch Ex As Exception
            'ShowError(Ex)
        End Try
    End Sub
    Public Sub WriteMemory(ByVal Address As Integer, ByVal Value() As Byte, ByVal Offset As Integer, ByVal Length As Integer)
        Try
            Dim Count1 As Integer
            For Count1 = 0 To Length - 1
                WriteMemory(Address + Count1, Value(Count1 + Offset), 1)
            Next
        Catch Ex As Exception
            'ShowError(Ex)
        End Try
    End Sub
    Public Sub WriteMemory(ByVal Address As Integer, ByVal Value As String)
        Try
            Dim Length As Integer = Value.Length
            For I As Integer = 0 To Length - 1
                WriteMemory(Address + I, Asc(Value.Chars(I)), 1)
            Next
            WriteMemory(Address + Length, 0, 1)
        Catch Ex As Exception
            'ShowError(Ex)
        End Try
    End Sub
    Public Sub WriteMemory(ByVal Address As Integer, ByVal Value As Double)
        Try
            Dim Buffer(0 To 7) As Byte
            Buffer = BitConverter.GetBytes(Value)
            For I As Integer = 0 To 7
                WriteMemory(Address + I, CInt(Buffer(I)), 1)
            Next
        Catch Ex As Exception
            'ShowError(Ex)
        End Try
    End Sub
    'Read Memory
    Public Sub ReadMemory(ByVal Address As Integer, ByRef Value As Double)
        Try
            Dim Buffer(7) As Byte
            Dim Temp As Integer
            For I As Integer = 0 To 7
                ReadMemory(Address + I, Temp, 1)
                Buffer(I) = CByte(Temp)
            Next
            Value = BitConverter.ToDouble(Buffer, 0)
        Catch Ex As Exception
            'ShowError(Ex)
        End Try
    End Sub
    Public Sub ReadMemory(ByVal Address As Integer, ByRef Value As Integer, ByVal Size As Integer)
        Try
            Dim mValue As Integer

            Dim GameReadWrite As Integer
            Dim PID As Integer = Game_Hwnd()
            GameReadWrite = OpenProcess(PROCESS_READ_WRITE_QUERY, False, PID)

            ReadProcessMemory(GameReadWrite, Address, mValue, Size, 0)
            Value = mValue

            CloseHandle(GameReadWrite)
        Catch Ex As Exception
            'ShowError(Ex)
        End Try
    End Sub
    Public Sub ReadMemory(ByVal Address As Integer, ByRef Value() As Byte, ByVal Length As Integer)
        Try
            Dim bytArray() As Byte
            Dim Count1 As Integer
            Dim tempInteger As Integer
            ReDim bytArray(Length - 1)
            For Count1 = 0 To Length - 1
                ReadMemory(Address + Count1, tempInteger, 1)
                bytArray(Count1) = CByte(tempInteger)
            Next
            Value = bytArray
        Catch Ex As Exception
            'ShowError(Ex)
        End Try
    End Sub
    Public Sub ReadMemory(ByVal Address As Integer, ByRef Value As String)
        Try
            Dim intChar As Integer
            Dim Count1 As Integer
            Dim strTemp As String
            strTemp = String.Empty
            Count1 = 0
            Do
                ReadMemory(Address + Count1, intChar, 1)
                If intChar <> 0 Then strTemp = strTemp & Chr(intChar)
                Count1 += 1
            Loop Until intChar = 0
            Value = strTemp
        Catch Ex As Exception
            'ShowError(Ex)
        End Try
    End Sub
    Public Sub ReadMemory(ByVal Address As Integer, ByRef Value As String, ByVal Length As Integer)
        Try
            Dim intChar As Integer
            Dim Count1 As Integer
            Dim strTemp As String
            strTemp = String.Empty
            For Count1 = 0 To Length - 1
                ReadMemory(Address + Count1, intChar, 1)
                strTemp = strTemp & Chr(intChar)
            Next
            Value = strTemp
        Catch Ex As Exception
            'ShowError(Ex)
        End Try
    End Sub
#End Region
    Function ReadInt(ByVal Address As Int32)
        Dim i As Int32
        ReadMemory(Address, i, 4)
        Return i
    End Function
    Sub WriteInt(ByVal Address As Int32, ByVal Value As Int32)
        WriteMemory(Address, Value, 4) ' We'll write a 4 bit to the address
    End Sub
End Module
Public Function Game_Hwnd() As Int32
Dim i As Int32 : Dim foundit As Boolean = False
For Each p As Process In Process.GetProcessesByName("Halo2") '' REMOVED orig. comment. NOT window Title :/
i = p.Id
foundit = True : Exit For
Next
If foundit = True Then
Return i
Else
MsgBox("Couldn't find Game")
Return 0
End If
End Function
Code:
Public Sub ReadMemory(ByVal Address As Integer, ByRef Value As Integer, ByVal Size As Integer)
        Try
            Dim mValue As Integer

            Dim GameReadWrite As Integer
            Dim PID As Integer = Game_Hwnd()                                        ''// CALLED HERE

            GameReadWrite = OpenProcess(PROCESS_READ_WRITE_QUERY, False, PID)

            ReadProcessMemory(GameReadWrite, Address, mValue, Size, 0)
            Value = mValue

            CloseHandle(GameReadWrite)
        Catch Ex As Exception
            'ShowError(Ex)
        End Try
    End Sub
Your memory code has it hardwired in to connect to halo. Did you keep getting the MsgBox("Couldn't find Game") ?


edit: this code is not a good example. For example Game_Hwnd returns a Process.ID but the function name, hwnd, suggests "Handle to Window". And a few other things. Just saying. Maybe try search for "ReadProcessMemory vb.net" here on mpgh to see how I did it.
 
Code logic fail

Code:
Public Function Game_Hwnd() As Int32
Dim i As Int32 : Dim foundit As Boolean = False
For Each p As Process In Process.GetProcessesByName("Halo2") '' REMOVED orig. comment. NOT window Title :/
i = p.Id
foundit = True : Exit For
Next
If foundit = True Then
Return i
Else
MsgBox("Couldn't find Game")
Return 0
End If
End Function
Code:
Public Function Game_Hwnd() As Int32
For Each p As Process In Process.GetProcessesByName("Halo2") 
Return p.Id '' why bother using the For anyway.
Next
MsgBox("Couldn't find Game")
Return 0
End Function
How I use it?
code = ReadMemory(&HC717F0, pidm, 4) - Doenst work
did you change this --> For Each p As Process In Process.GetProcessesByName("Halo2")

???

should be "gta4" or whatever.
Hello.
Are you using the professional Hotkey Instance or the normal-used standarts?
Posts 1–15 of 33 · Page 1 of 3

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us