First at all, using the indexer of the MemorySharp
object already rebases the pointer to the base address of the main module of the process. So, you don't need to use your function GetBaseAddress
and you can declare your pointer/offsets like this:
var healthPtr = new IntPtr(0x0036B1C8);
int[] offsets = { 0x39c, 0x16c };
Now read the value of the pointer
healthPtr = m[healthPtr].Read<IntPtr>(); // The pointer is automatically rebased
Browse the pointer chain using the offsets
foreach (var offset in offsets)
{
healthPtr = m[healthPtr + offset, false].Read<IntPtr>(); // false is here to avoid rebasing
}
Note the second parameter set to false
. It states that the address must not be rebased to the main module of the process.
Also, it's important to use the offsets after a first reading, else what is the purpose to declare an offset instead of directly add the value to the address. :)
I think the line setting the var healthLocation
is not needed and will read unknown memory address. Are you sure you want to do that ?
This error:
"An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in MemorySharp.dll Additional information: The relative address cannot be greater than the main module size."
is thrown because MemorySharp already rebases the the pointer if you do not set the second parameter to false
(as explained above).
Let me know if it's all right for you.