Code:
'Memory hacking module, don't change anything here
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Imports System****
Module Memory
<DllImport("kernel32.dll")> _
Public Function ReadProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, <[In](), Out()> ByVal buffer As Byte(), ByVal size As UInt32, ByRef lpNumberOfBytesRead As IntPtr) As Int32
End Function
<DllImport("kernel32.dll")> _
Public Function WriteProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, <[In](), Out()> ByVal buffer As Byte(), ByVal size As UInt32, ByRef lpNumberOfBytesWritten As IntPtr) As Int32
End Function
Public Function WriteInt32(ByVal P As Process, ByVal memAdr As Int32, ByVal value As Integer) As Boolean
Return WriteBytes(P, memAdr, BitConverter.GetBytes(value), 4)
End Function
Public Function ReadInt32(ByVal P As Process, ByVal memAdr As Int32) As Integer
Return BitConverter.ToInt32(ReadBytes(P, memAdr, 4), 0)
End Function
Public Function WriteShort(ByVal P As Process, ByVal memAdr As Int32, ByVal value As Short) As Boolean
Return WriteBytes(P, memAdr, BitConverter.GetBytes(value), 2)
End Function
Public Function ReadShort(ByVal P As Process, ByVal memAdr As Int32) As Short
Return BitConverter.ToInt16(ReadBytes(P, memAdr, 2), 0)
End Function
Public Function WriteFloat(ByVal P As Process, ByVal memAdr As Int32, ByVal value As Single) As Boolean
Return WriteBytes(P, memAdr, BitConverter.GetBytes(value), 4)
End Function
Public Function ReadFloat(ByVal P As Process, ByVal memAdr As Int32) As Single
Return BitConverter.ToSingle(ReadBytes(P, memAdr, 4), 0)
End Function
Public Function WriteByte(ByVal P As Process, ByVal memAdr As Int32, ByVal value As Byte) As Boolean
Return WriteBytes(P, memAdr, BitConverter.GetBytes(value), 1)
End Function
Public Function ReadByte(ByVal P As Process, ByVal memAdr As Int32) As Byte
Return BitConverter.ToString(ReadBytes(P, memAdr, 1), 0)
End Function
Private Function ReadBytes(ByVal P As Process, ByVal memAdr As Long, ByVal bytesToRead As UInteger) As Byte()
Dim ptrBytesRead As IntPtr
Dim buffer As Byte() = New Byte(bytesToRead - 1) {}
ReadProcessMemory(P.Handle, New IntPtr(memAdr), buffer, bytesToRead, ptrBytesRead)
Return buffer
End Function
Public Function WriteBytes(ByVal P As Process, ByVal memAdr As Long, ByVal bytes As Byte(), ByVal length As UInteger) As Boolean
Dim bytesWritten As IntPtr
Dim result As Integer = WriteProcessMemory(P.Handle, New IntPtr(memAdr), bytes, length, bytesWritten)
Return result <> 0
End Function
Public Function StrToByteArray(ByVal str As String) As Byte() 'Function to write Unicode text into the memory. Use it with the WriteBytes function like in the example: WriteBytes(p, Adr2 + &H0, StrToByteArray(TEXT), StrToByteArray(TEXT).Length)
Dim encoding As New System.Text.UnicodeEncoding() 'You may have to overwrite the string with 00 Bytes first to avoid a combination of the original and the new string as result, like if the new text is "One" and the old is "Blablabla"
Return encoding.GetBytes(str) 'after changing it would be "Oneblabla" and not "One" if you don't overwrite the old string. To overwrite it use this in the code BEFORE you overwrite it with the new text:
End Function 'WriteBytes(p, Adr1 + &H0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 24). Write two 0s for every letter of the old text, replace the 24 with the amount of 0s and don't forget to replace the &H0 with the last offset of your pointer.
Public Function WriteInt64(ByVal P As Process, ByVal memAdr As Int64, ByVal value As Integer) As Boolean
Return WriteBytes(P, memAdr, BitConverter.GetBytes(value), 4)
End Function
Public Function ReadInt64(ByVal P As Process, ByVal memAdr As Int64) As Integer
Return BitConverter.ToInt64(ReadBytes(P, memAdr, 10), 0)
End Function
Public Function WriteShort(ByVal P As Process, ByVal memAdr As Int64, ByVal value As Short) As Boolean
Return WriteBytes(P, memAdr, BitConverter.GetBytes(value), 2)
End Function
Public Function ReadShort(ByVal P As Process, ByVal memAdr As Int64) As Short
Return BitConverter.ToInt16(ReadBytes(P, memAdr, 10), 0)
End Function
Public Function WriteFloat(ByVal P As Process, ByVal memAdr As Int64, ByVal value As Single) As Boolean
Return WriteBytes(P, memAdr, BitConverter.GetBytes(value), 4)
End Function
Public Function ReadFloat(ByVal P As Process, ByVal memAdr As Int64) As Single
Return BitConverter.ToSingle(ReadBytes(P, memAdr, 10), 0)
End Function
Public Function WriteByte(ByVal P As Process, ByVal memAdr As Int64, ByVal value As Byte) As Boolean
Return WriteBytes(P, memAdr, BitConverter.GetBytes(value), 1)
End Function
Public Function ReadByte(ByVal P As Process, ByVal memAdr As Int64) As Byte
Return BitConverter.ToString(ReadBytes(P, memAdr, 10), 0)
End Function
Public Function WriteMemory(ByVal address As Long, ByVal value As Object) As Boolean
End Function
End Module