0

So I am making an AI BOT for game Bloons TD6, but for it to work I need to get money value so he knows when he can buy something. For that I decided to find pointer to in-game money but I don't know how to read memory with python, I managed to do it in cpp but for bot to work I need it in python. I already managed to get PID, now I just need to read an address from memory.

Also important to mention is that value that I want to read is double.

PROCESS_ALL_ACCESS = 0x1F0FFF
HWND = win32ui.FindWindow(None,"BloonsTD6").GetSafeHwnd()
PID = win32process.GetWindowThreadProcessId(HWND)[1]

1 Answers1

0

You could try Pymem; here you can find a quickstart showing how you can read/write integer values from/to process memory: https://pymem.readthedocs.io/en/latest/quickstart.html.

You'll find this simple example (there's actually a typo in it, it's pm.process_id, not process_id):

from pymem import Pymem

pm = Pymem('notepad.exe')
print('Process id: %s' % pm.process_id)
address = pm.allocate(10)
print('Allocated address: %s' % address)
pm.write_int(address, 1337)
value = pm.read_int(address)
print('Allocated value: %s' % value)
pm.free(address)

In the same way it is possible to read/write a double by using the read_double() and write_double() functions. You can find some docs in here: https://pymem.readthedocs.io/en/documentation/api.html

Also check this out: reading data from process' memory with Python

  • well if I try to read certain address, this happens: Traceback (most recent call last): File "C:/Users/Oskar szbsz/Desktop/BTD6/tester.py", line 4, in print(pm.read_double(0x1A45A28C2A8)) File "C:\Users\Oskar szbsz\PycharmProjects\NewOne\venv\lib\site-packages\pymem\__init__.py", line 749, in read_double raise pymem.exception.MemoryReadError(address, struct.calcsize('d'), e.error_code) pymem.exception.MemoryReadError: Could not read memory at: 1805398885032, length: 8 - GetLastError: 299 – koksem1234 Dec 28 '20 at 20:54
  • This is likely due to the fact that the memory address you're trying to read is protected (PAGE_GUARD or PAGE_NOACCESS). Did it work with other memory addresses? Could you read that address with your C++ program? – humble_coder Dec 28 '20 at 21:23
  • I think you are right about this protection cause now that I'm trying with cpp, I managed to read the address in cpp but I had to use some extraordinary ways to do so. Do you have idea how to read it anyways ? – koksem1234 Dec 29 '20 at 13:02