To do the attach you're going to want to do something like this:
Code:
Declare Function ReadProcessMemoryFloat Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Single, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
Declare Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
Dim blnAttachedToGame As Boolean = False
Dim readHandle As Integer 'IntPtr
Dim intMemBasePlayer As Integer
Dim intMemBaseSWTOR As Integer
Private Function getBaseAddress(ByVal oProcess As Process, ByVal strBase As String) As Int32
Try
Dim ffxiMainIndex As Integer = 0
For i = 0 To oProcess.Modules.Count - 1
If oProcess.Modules.Item(i).ModuleName.ToLower = strBase Then
oMainIndex = i
Exit For
End If
Next
Return oProcess.Modules.Item(oMainIndex).BaseAddress.ToInt32
Catch ex As Exception
Return Nothing
End Try
End Function
Sub AttachGame()
Try
Dim strProcessName As String = "swtor"
Dim objProcesses As Process() = Process.GetProcessesByName(strProcessName)
Dim objProcess As Process
For Each objProcess In objProcesses
readHandle = OpenProcess(PROCESS_VM_READ, False, CUInt(objProcess.Id))
Dim intTmpBaseMemMan As Integer = getBaseAddress(objProcess, "memoryman.dll")
intMemBaseSWTOR = getBaseAddress(objProcess, "swtor.exe")
Dim lngStep1 As Long = 0
Dim lngStep2 As Long = 0
Dim lngStep3 As Long = 0
Dim lngStep4 As Long = 0
Dim lngStep5 As Long = 0
ReadProcessMemory(readHandle, intTmpBaseMemMan + &H27E8C, lngStep1, 4, Nothing) 'F4540000
ReadProcessMemory(readHandle, lngStep1 + &H798, lngStep2, 4, Nothing) 'F4540798
ReadProcessMemory(readHandle, lngStep2 + &H504, lngStep3, 4, Nothing) 'ED9E06E
ReadProcessMemory(readHandle, lngStep3 + &H14, lngStep4, 4, Nothing) 'F1880200
ReadProcessMemory(readHandle, lngStep4 + &H8, lngStep5, 4, Nothing) 'F613F068
intMemBasePlayer = lngStep5
If intMemBasePlayer <> 0 Then
WriteLog("Attached to SWTOR.EXE [" & objProcess.Id & "]")
blnAttachedToGame = True
Exit For
End If
Next
If intMemBasePlayer = 0 Then WriteLog("Error: SWTOR.EXE not found")
Catch ex As Exception
WriteLog("Error attaching>> " & ex.ToString)
End Try
End Sub
Then to grab values from memory:
Code:
ReadProcessMemoryLong(readHandle, intMemBasePlayer + &H28, intLastTarget, 4, Nothing)
ReadProcessMemoryFloat(readHandle, intMemBasePlayer + &H40, sngHealth, 4, Nothing) 'F4072770
ReadProcessMemoryFloat(readHandle, intMemBasePlayer + &H80, sngDistanceToTarget, 4, Nothing) 'F40727B0
ReadProcessMemoryFloat(readHandle, intMemBasePlayer + &H100, sngPlayerX, 4, Nothing) 'F4072830
ReadProcessMemoryFloat(readHandle, intMemBasePlayer + &H104, sngPlayerY, 4, Nothing) 'F4072834
ReadProcessMemoryFloat(readHandle, intMemBasePlayer + &H108, sngPlayerZ, 4, Nothing) 'F4072838
ReadProcessMemoryFloat(readHandle, intMemBasePlayer + &H114, sngPlayerAngle, 4, Nothing) 'F4072844
sngDistanceToTarget = sngDistanceToTarget * 10
ReadProcessMemoryFloat(readHandle, intMemBaseSWTOR + &H1080AC4, fltPlayerX, 4, Nothing)
ReadProcessMemoryFloat(readHandle, intMemBaseSWTOR + &H1080ACC, fltPlayerY, 4, Nothing)
ReadProcessMemoryFloat(readHandle, intMemBaseSWTOR + &H1080AC8, fltPlayerZ, 4, Nothing)
ReadProcessMemoryFloat(readHandle, intMemBaseSWTOR + &H1085570, fltTargetX, 4, Nothing)
ReadProcessMemoryFloat(readHandle, intMemBaseSWTOR + &H1085578, fltTargetY, 4, Nothing)
ReadProcessMemoryFloat(readHandle, intMemBaseSWTOR + &H1085574, fltTargetZ, 4, Nothing)