Hi.
I've also been looking for how to write to a process memory. I have a code written by Bruno D (?) that reads from a process memory, so I help with that (I've updated it to 8.52, and added a lvl adress), you will need a button and 2 textboxes:
Code:
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
'The exp address in the tibia memory
Public EXP_ADDRESS As IntPtr = &H633E84
Public LVL_ADDRESS As IntPtr = &H633E80
Public Const PROCESS_READ As UInteger = 16
'Api's
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function GetClassName(ByVal hWnd As IntPtr, ByVal className As StringBuilder, _
ByVal maxCharCount As Integer) As Integer
End Function
<DllImport("kernel32.dll")> _
Public Shared Function OpenProcess(ByVal dwDesiredAccess As UInt32, _
ByVal bInheritHandle As Int32, ByVal dwProcessId As UInt32) As IntPtr
End Function
<DllImport("kernel32.dll")> _
Public Shared Function ReadProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, _
ByVal buffer As Byte(), ByVal size As UInt32, _
ByRef lpNumberOfBytesRead As IntPtr) As Int32
End Function
<DllImport("kernel32.dll")> _
Public Shared Function CloseHandle(ByVal hObject As IntPtr) As Int32
End Function
Private Sub UpdatePlayerExp()
'try to find the tibia client
Dim query = From proc As Process In Process.GetProcesses _
Where (GetProcessClassName(proc).Equals("tibiaclient", StringComparison.CurrentCultureIgnoreCase))
Dim tibiaProcesses() As Process = query.ToArray()
If (tibiaProcesses.Length) Then
'get the handle for the first client found..
Dim processHandle As IntPtr = OpenProcess(PROCESS_READ, 0, tibiaProcesses(0).Id)
Dim buffer(0 To 3) As Byte
ReadProcessMemory(processHandle, EXP_ADDRESS, buffer, 4, 0)
TextBox1.Text = BitConverter.ToUInt32(buffer, 0).ToString("#,#") & " EXP"
ReadProcessMemory(processHandle, LVL_ADDRESS, buffer, 4, 0)
ReadProcessMemory(processHandle, LVL_ADDRESS, buffer, 4, 0)
TextBox2.Text = BitConverter.ToUInt32(buffer, 0).ToString & " LVL"
CloseHandle(processHandle)
Else
MsgBox("Please start the tibia and login first!", MsgBoxStyle.Information, "Error")
End If
End Sub
Private Function GetProcessClassName(ByVal process As Process) As String
Dim className As New StringBuilder(20)
GetClassName(process.MainWindowHandle, className, className.Capacity)
Return className.ToString()
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
UpdatePlayerExp()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
UpdatePlayerExp()
End Sub
End Class
Now all I wondering, as said, is how to write to the process, I've googled but it didn't helped me so much =(