Okay, let's break down how to approach reading memory from osu!stable using Python and pymem.
1. Understanding Memory Patterns and Pointers
- Dynamic Addresses: When you run a program like
osu!.exe, the operating system assigns it memory locations (addresses) for its code and data (like your score, combo, HP, current map time, etc.). These addresses can often change each time you start the game[1].
- Static Pointers & Offsets: To reliably find data despite changing addresses, developers often use pointers[2]. A "base address" (often the start address of the main game module,
osu!.exe) plus a series of "offsets" can lead to a specific value[3]. Think of it like directions: start at the main building (osu!.exe base address), go to the 3rd floor (+offset1), then the 5th room (+offset2), and look in the second drawer (+offset3) to find the score[2]. This chain (Base + Offset1 -> + Offset2 -> + Offset3 -> Value) is often stable even if the initial base address changes slightly between game launches or updates.
- Signature Scanning (Pattern Scanning): Sometimes, even base addresses or pointer chains change after major game updates[2]. Signature scanning involves searching the game's memory for a unique sequence of bytes (a "pattern") that is known to be near the data you want or part of the code that accesses it. Once the pattern is found, you can calculate the address of the data relative to the pattern's location[2]. This is more robust against updates but more complex to implement.
pymem itself doesn't have built-in pattern scanning, but you can read memory regions and search manually or use other libraries alongside it.
- Finding Them: Tools like Cheat Engine are commonly used to find these pointers and patterns by searching for known values (like your score), seeing how they change, and then finding what code accesses that memory or tracing back pointers[3]. Results are often shared in online communities (forums, GitHub). [5, 12]
2. Finding osu!stable Memory Information[2]
Based on the search results, finding specific, up-to-date, publicly listed memory patterns or static pointer offsets for osu!stable is challenging.
- gosumemory: This project [8, 18] is a well-known memory reader for osu!, primarily used for displaying real-time stats in OBS or other applications[2]. While it's written in Go, its source code [8] is a valuable resource. It uses memory patterns (
mem.ResolvePatterns) to find base addresses for various data structures (menu state, gameplay data, etc.)[2]. Analyzing its source code, particularly the parts defining patterns and structures, is likely the most reliable way to get current information[2]. It mentions using signatures from "Piotrekol and his ProcessMemoryDataFinder" [18][2][4].
- Cheat Engine Approach: Several sources [2, 5, 12] mention using Cheat Engine to find addresses and pointers manually. This involves searching for values (like game time [12], score, or combo [5]) and then using Cheat Engine's features to find static pointers or code that accesses these values[1]. A blog post [12] details finding the game time address using Cheat Engine by searching for increasing values and then finding what writes to the address to identify a signature[2].
- Direct Addresses/Patterns: Publicly listing exact patterns or multi-level pointers is often avoided or quickly becomes outdated due to game updates [2]. Projects like gosumemory [8] are more likely to keep their internal patterns updated.
3. Reading Memory with pymem (Python)[2][5][6]
Here's a conceptual Python script using pymem to read game memory, focusing on the pointer chain method, which is more straightforward with pymem than pattern scanning.
Important Considerations & Disclaimer:
- Terms of Service: Accessing game memory, even just for reading, might be against osu!'s Terms of Service[2]. Doing so could potentially lead to restrictions or bans on your account. Proceed at your own risk. This information is for educational purposes only[2].
- Game Updates: Memory addresses, pointers, and patterns will change when the game updates [2, 12]. Code based on specific addresses or patterns will break. Reliable tools often use signature scanning [12] or are updated frequently by communities (like gosumemory [8])[2].
- Finding Pointers: The example below uses hypothetical pointers/offsets. You would need to find the actual, current pointers for
osu!stable using methods described above (Cheat Engine, analyzing gosumemory source).
import pymem
import pymem.process
import time
import struct # Needed for reading different data types
# --- DISCLAIMER ---
# Accessing game memory can violate the game's Terms of Service and lead to bans[2].
# This code is for EDUCATIONAL PURPOSES ONLY[2]. Use at your own risk.
# Pointers and offsets WILL change with game updates. These are placeholders.
# --- Placeholder Pointers/Offsets ---
# You MUST find the correct, current values for these using Cheat Engine or by
# analyzing projects like gosumemory[2]. These are examples ONLY.
# Example: Hypothetical pointer chain for Score
SCORE_BASE_OFFSET = 0x01CF2A30 # Example offset relative to osu!.exe base
SCORE_OFFSETS = [0x34, 0x18, 0x24, 0x88] # Example chain of offsets
# Example: Hypothetical pointer chain for Map Time
TIME_BASE_OFFSET = 0x01D7B4C8 # Example offset relative to osu!.exe base
TIME_OFFSETS = [0x5C, 0x0, 0x34, 0x28] # Example based on source [12] / [17]'s structure
# Example: Direct pointer/signature result (less common for dynamic values)[2]
# Sometimes a signature scan might resolve to a fairly stable pointer address itself[2]
# Let's pretend a signature scan found the HP address is always at osu!.exe + 0x12345678
HP_STATIC_OFFSET = 0x12345678 # Completely hypothetical
PROCESS_NAME = "osu!.exe"[2]
def get_pointer_address(pm, base, offsets):
""" Follows a pointer chain to get the final memory address. """
try:
# Read the value at the base address (this value is the next address)
# Use read_bytes and struct.unpack for pointer size (usually 4 bytes for 32-bit, 8 for 64-bit)
# osu!stable is 32-bit, so pointers are 4 bytes ('I' for unsigned int)
addr = pm.read_uint(base)
if not addr:
# print(f"Warning: Read null address at base: {hex(base)}")
return None
# Follow the offsets
for i, offset in enumerate(offsets):
if i == len(offsets) - 1:
# This is the last offset, add it to the current address
addr += offset
# print(f" -> Final Offset Add: {hex(offset)} -> {hex(addr)}")
else:
# Read the address at the current address + offset
# print(f" -> Reading at {hex(addr)} + {hex(offset)} = {hex(addr + offset)}")
new_addr = pm.read_uint(addr + offset)
if not new_addr:
# print(f"Warning: Read null address at offset {i}: {hex(addr + offset)}")
return None
addr = new_addr
# print(f" -> New Address: {hex(addr)}")
return addr
except pymem.exception.MemoryReadError as e:
# print(f"Memory Read Error following pointers: {e}")
return None
except Exception as e:
# print(f"An unexpected error occurred: {e}")
return None
try:
print(f"Attempting to open process: {PROCESS_NAME}")
pm = pymem.Pymem(PROCESS_NAME)
print(f"Process found! PID: {pm.process_id}")
# Get the base address of the main module (osu!.exe)
# Sometimes process.module_from_name is more reliable
try:
game_module = pymem.process.module_from_name(pm.process_handle, PROCESS_NAME)
if not game_module:
raise Exception(f"Could not find module {PROCESS_NAME}")
base_address = game_module.lpBaseOfDll
print(f"Base address of {PROCESS_NAME}: {hex(base_address)}")
except Exception as e:
print(f"Error getting module base address: {e}")
print("Falling back to pm.base_address (might be less reliable)")
base_address = pm.base_address # Fallback, might not be the module base
if not base_address:
raise Exception("Could not determine base address.")
print(f"Fallback base address: {hex(base_address)}")
while True:
try:
# --- Read Score (using pointer chain) ---
score_ptr_base = base_address + SCORE_BASE_OFFSET
score_address = get_pointer_address(pm, score_ptr_base, SCORE_OFFSETS)
if score_address:
score = pm.read_int(score_address) # osu! score is usually an int
print(f"Score Address: {hex(score_address)} | Score: {score}", end=" | ")
else:
print("Score: N/A", end=" | ")
# --- Read Map Time (using pointer chain) ---
time_ptr_base = base_address + TIME_BASE_OFFSET
time_address = get_pointer_address(pm, time_ptr_base, TIME_OFFSETS)
if time_address:
# Time is often an integer (milliseconds)
map_time_ms = pm.read_int(time_address)
print(f"Time Address: {hex(time_address)} | Time (ms): {map_time_ms}", end=" | ")
else:
print("Time: N/A", end=" | ")
# --- Read HP (using direct offset - less common for dynamic values) ---
hp_address = base_address + HP_STATIC_OFFSET
try:
# HP is often a float or double[2]. Let's try double (8 bytes)
hp = pm.read_double(hp_address)
print(f"HP Address: {hex(hp_address)} | HP: {hp:.2f}")
except pymem.exception.MemoryReadError:
print(f"HP Address: {hex(hp_address)} | HP: Error Reading")
except Exception as e:
print(f"HP Address: {hex(hp_address)} | HP: Error ({e})")
print("-" * 10)
except pymem.exception.MemoryReadError as e:
print(f"\nError reading memory: {e}. Was the game closed or map changed?")
except Exception as e:
print(f"\nAn unexpected error occurred in the loop: {e}")
time.sleep(1) # Read every second
except pymem.exception.ProcessNotFound:
print(f"Error: Process '{PROCESS_NAME}' not found. Is osu! running?")
except Exception as e:
print(f"An error occurred: {e}")
Explanation:
- Import
pymem: Imports necessary libraries.
- Disclaimer & Placeholders: Stresses the risks and that the provided offsets/pointers are examples that must be replaced with current, correct values[2].
PROCESS_NAME: Sets the target executable name[2].
get_pointer_address Function:
- Takes the
Pymem object (pm), a starting base address (like module_base + pointer_offset), and a list of offsets[5][6].
- It reads the 4-byte value (pointer) at the current address using
pm.read_uint().
- For each offset in the list (except the last), it adds the offset to the address it just read and reads the next address from that new location[2].
- For the last offset, it adds the offset to the final address read, returning the final memory location where the actual data (e.g., score) is stored[2]. [13, 17] provide context on this multi-level pointer concept[2].
- Includes basic error handling for null pointers or read errors[2].
- Main Block:
- Uses a
try...except block to handle cases where the process isn't found [16][2].
pm = pymem.Pymem(PROCESS_NAME): Attaches pymem to the osu[2]! process.
game_module = pymem.process.module_from_name(...): Gets the base address of osu!.exe[2]. This is generally more reliable than pm.base_address[2].
- Loop: Continuously tries to read the data.
- Reading Values:
- Calculates the initial address for each pointer chain (
base_address + POINTER_BASE_OFFSET)[2].
- Calls
get_pointer_address to resolve the chain to the final data address.
- If the address is valid, uses
pm.read_int(), pm.read_double(), etc. [6, 9, 10] to read the data based on its expected type (int for score/time, double or float for HP)[2].
- Includes error handling within the loop for memory read errors (e.g., if the game state changes abruptly or closes).
time.sleep(1): Pauses to avoid excessive CPU usage[2].
Remember to install pymem (pip install pymem) and find the actual current pointers/offsets for osu!stable for this code to work. Analyzing the gosumemory project [8, 18] or using Cheat Engine [5, 12] are the most common ways to find this information.