m1ndgames_AI How do I cheat?
  Reputation: 0
  Joined: 07 Mar 2021 Posts: 3
 
  | 
		
			
				 Posted: Sun Mar 07, 2021 9:33 am    Post subject: Python cTypes - int too long to convert | 
				       | 
			 
			
				
  | 
			 
			
				Hi,
 
im trying to access the health values for streetfighter2 in snes emu via python ctypes, and i get an error:
 
 
 	  | Code: | 	 		  (skullgirls) C:\skullgirls>serpent play sf2 SerpentryuGameAgent
 
{'width': 512, 'height': 448, 'x_offset': 8, 'y_offset': 51}
 
Using TensorFlow backend.
 
2021-03-07 16:25:08.376221: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
 
5368709120
 
<class 'int'>
 
Traceback (most recent call last):
 
  File "c:\anaconda3\envs\skullgirls\lib\runpy.py", line 193, in _run_module_as_main
 
    "__main__", mod_spec)
 
  File "c:\anaconda3\envs\skullgirls\lib\runpy.py", line 85, in _run_code
 
    exec(code, run_globals)
 
  File "C:\Anaconda3\envs\skullgirls\Scripts\serpent.exe\__main__.py", line 7, in <module>
 
  File "c:\anaconda3\envs\skullgirls\lib\site-packages\serpent\serpent.py", line 52, in execute
 
    command_function_mapping[command](*sys.argv[2:])
 
  File "c:\anaconda3\envs\skullgirls\lib\site-packages\serpent\serpent.py", line 369, in play
 
    game.play(game_agent_class_name=game_agent_name, frame_handler=frame_handler)
 
  File "c:\anaconda3\envs\skullgirls\lib\site-packages\serpent\game.py", line 201, in play
 
    raise e
 
  File "c:\anaconda3\envs\skullgirls\lib\site-packages\serpent\game.py", line 192, in play
 
    game_agent.on_game_frame(game_frame, frame_handler=frame_handler, **kwargs)
 
  File "c:\anaconda3\envs\skullgirls\lib\site-packages\serpent\game_agent.py", line 115, in on_game_frame
 
    frame_handler(game_frame, **kwargs)
 
  File "C:\skullgirls\plugins\SerpentryuGameAgentPlugin\files\serpent_ryu_game_agent.py", line 157, in handle_play
 
    (self.p1hp, self.p2hp) = readhp()
 
  File "C:\skullgirls\plugins\SerpentryuGameAgentPlugin\files\helpers\memory.py", line 22, in readhp
 
    r1 = ReadProcessMemory(processHandle, BaseAddress + 0x008D8E38, byref(player_one), 2, byref(numRead))
 
ctypes.ArgumentError: argument 2: <class 'OverflowError'>: int too long to convert
 
 
(skullgirls) C:\skullgirls> | 	  
 
 
my code:
 
 
 	  | Code: | 	 		  import ctypes
 
import win32process
 
import win32ui
 
from ctypes import *
 
 
def readhp():
 
    ReadProcessMemory = windll.kernel32.ReadProcessMemory
 
 
    PROCESS_ALL_ACCESS = 0x1F0FFF
 
    HWND = win32ui.FindWindow(None, u"StreetFighterIITurbo - Snes9x 1.60").GetSafeHwnd()
 
    PID = win32process.GetWindowThreadProcessId(HWND)[1]
 
    processHandle = ctypes.windll.kernel32.OpenProcess(PROCESS_ALL_ACCESS, False, PID)
 
 
    BaseAddress = win32process.EnumProcessModules(processHandle)[0]
 
    numRead = c_int()
 
 
    print(str(BaseAddress))
 
    print(str(type(BaseAddress)))
 
 
    # read fighters hp:
 
    player_one = c_int()
 
    r1 = ReadProcessMemory(processHandle, BaseAddress + 0x008D8E38, byref(player_one), 2, byref(numRead))
 
    print(str(r1))
 
    print(str(type(r1)))
 
 
    p1hp = int(player_one.value)
 
    player_two = c_int()
 
    ReadProcessMemory(processHandle, BaseAddress + 0x008D8CB8, byref(player_two), 2, byref(numRead))
 
    p2hp = int(player_two.value)
 
 
    # Make sure HP cant be lower than 0
 
    if p1hp < 0 or p1hp == 255:
 
        p1hp = 0
 
    if p2hp < 0 or p2hp == 255:
 
        p2hp = 0
 
 
    # Return HP
 
    print(str(p1hp))
 
    print(str(p2hp))
 
 
    return p1hp, p2hp | 	  
 
 
CheatEngine Screenshot that shows the address:
 
s20.directupload .net/images/210307/gwrf5eah.png
 
 
The same code worked for the game Skullgirls, im not sure what the issue is... snesx is 64bit, python is 64bit...
 
 
Any guesses?
 | 
			 
		  |