Originally Posted by
Cypher
Eeeew. Noone should EVER be doing the coord scanning to get the address of an object.
Very true. But give the poor man a break, I doubt he'd understand or comprehend anything further past that.
I'll edit my post with some code if I get around to it..
EDIT:
Oh, the horrid coordinate scan function. But here it is..
Code:
Public Sub FindEntity()
If (processes.Length > 0) Then
' Lookup StaticX
MemAPI.Peek(gproc, Player.locBase, ByteA)
' Convert to 8byte to scan faster
Dim compare As Int64 = System.BitConverter.ToInt64(ByteA, 0) ' Int64, it's purpose was to be used for faster scans
Dim levelCompare As Integer
' Where to start looking
Dim i As Integer = &H10000BF8
' Declare compare and finished variables
Dim current As Single
Dim done As Integer = 0
While i < &H20000BF8 And done < 1
MemAPI.Peek(gproc, i, ByteA)
current = System.BitConverter.ToInt64(ByteA, 0)
If current = compare Then
' Recheck by comparing a static level and a level offset located in the Player entity
MemAPI.Peek(gproc, i - &HBF8 + Player.levelNonStatic, ByteA) ' LevelNonStatic would be to another static address storing the Level, just for comparison reasons
levelCompare = ByteA(0)
MemAPI.Peek(gproc, Player.level, ByteA)
If ByteA(0) = levelCompare Then
' The check has passed, the entity was found
done = 1
End If
Else
If i = &H1FFFFBF8 Then
done = 2
End If
i += &H1000
' The if statement once had meaning, but I coded this like 2 years ago
End If
End While
If done = 1 Then
' This is thrown when the scan has successfully identified the Player entity
Player.entity = i - &HBF8 ' Player object is the Scan - the scan offset, in this case the X coord(?)
Player.entityFound = True ' This is in place for a scrub Found boolean
' Player was found, rejoice and call functions to read offsets from your new Player object.
ElseIf done = 2 Then
' This error is thrown when the scan has reached the end of the memory and has failed to find the player.
Exit Sub
Else
Exit Sub ' Throw an error - Player not found
End If
Else
Exit Sub ' Throw an error - Fail
End If
End Sub
Really, I browsed over the code and it looks okay. Just one of the scrub subs I coded up when I was fiddling. Use it as an example and plug-in current offsets.
Also the code for "MemAPI.vb"
Code:
Imports System
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Public Class MemAPI
'The only things you should have to change in here would be if you want to add more
'standard functions for reading and writing.
'So enough comments in here :P
<DllImport("kernel32.dll")> _
Private Shared Function ReadProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, _
ByVal lpBuffer As Byte(), ByVal nSize As Integer, ByVal lpNumberOfBytesRead As Byte) As Boolean
End Function
<DllImport("kernel32.dll")> _
Public Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, _
ByVal lpBuffer As Byte(), ByVal nSize As Integer, ByVal lpNumberOfBytesWritten As Byte) As Boolean
End Function
Public Shared Function Peek(ByVal proc As Process, ByVal address As Integer, ByVal data As Byte()) As Boolean
Return ReadProcessMemory(proc.Handle, address, data, data.Length, 0)
End Function
Public Shared Function Poke(ByVal proc As Process, ByVal address As Integer, ByVal data As Byte()) As Boolean
Return WriteProcessMemory(proc.Handle, address, data, data.Length, 0)
End Function
End Class
Gah, ugly mess of ugly.