Skip to main content

Memory manager for hooking and manipulating game memory

Project description

Sure, here's the complete and updated description of memory_manager in English, including the new trigger features, usage examples, and detailed explanations.

Memory Manager

memory_manager is a Python package designed to facilitate hooking and manipulating game memory using the pymem library. This package simplifies the process of reading and writing memory addresses for various in-game variables, such as currency and weapon ammo, providing an easy-to-use library.

Features

  • Hook into a game's process using pymem.
  • Read and write different data types (e.g., integers, floats) at specified memory addresses.
  • Support for both constant and recalculated pointers.
  • Simple and clear API for memory manipulation.
  • Manage triggers to monitor changes in memory values and execute callback functions.

Installation

You can install memory_manager via pip:

pip install memory_manager

Usage

Basic Setup

To get started, import the MemoryManager class and use the hook method to attach to the game's process and module.

from memory_manager import MemoryManager

# Initialize the memory manager and hook into the game's process and module
process_name = "game_name"
module_name = "game_module"
pointers = {
    "Health": {
        "Address": 0xB6,
        "Offsets": [0x1A, 0x2B, 0x3C],
        "Type": "4 Bytes",
        "Constant": True
    },
    "Gold": {
        "Address": 0x1DE,
        "Offsets": [0x4D, 0x5E, 0x6F],
        "Type": "4 Bytes",
        "Constant": False
    },
    "PlayerStats": {
        "Stamina": {
            "Address": 0x2F,
            "Offsets": [0xA, 0xB, 0xC],
            "Type": "Float",
            "Constant": True
        },
        "Experience": {
            "Address": 0x3A,
            "Offsets": [0xD, 0xE],
            "Type": "2 Bytes",
            "Constant": True
        }
    }
}

mm = MemoryManager()
pointers = mm.hook(process_name, module_name, pointers)

Reading and Writing Memory

Once you've hooked into the game's process, you can read and write memory values using the Get and Set methods attached to each pointer.

Reading Memory

# Read the value of health
health = pointers["Health"]["Get"]()
print(f"Current health: {health}")

# Read the value of gold
gold = pointers["Gold"]["Get"]()
print(f"Current gold: {gold}")

# Read the value of stamina
stamina = pointers["PlayerStats"]["Stamina"]["Get"]()
print(f"Current stamina: {stamina}")

# Read the value of experience
experience = pointers["PlayerStats"]["Experience"]["Get"]()
print(f"Current experience: {experience}")

Writing Memory

# Set the value of health
new_health_value = 100
pointers["Health"]["Set"](new_health_value)

# Set the value of gold
new_gold_value = 9999
pointers["Gold"]["Set"](new_gold_value)

# Set the value of stamina
new_stamina_value = 75.5
pointers["PlayerStats"]["Stamina"]["Set"](new_stamina_value)

# Set the value of experience
new_experience_value = 5000
pointers["PlayerStats"]["Experience"]["Set"](new_experience_value)

Handling Errors

The memory_manager package is designed to handle errors gracefully. If a memory read or write operation fails, the functions will return False instead of raising an exception.

# Attempt to read memory
success = pointers["Health"]["Get"]()
if not success:
    print("Failed to read health value.")

# Attempt to write memory
success = pointers["PlayerStats"]["Experience"]["Set"](new_experience_value)
if not success:
    print("Failed to write new experience value.")

Advanced Usage

Custom Data Types

You can extend the MemoryManager to support additional data types by modifying the read_funcs and write_funcs dictionaries.

# Add support for 8-byte integers
mm.read_funcs["8 Bytes"] = mm.mem.read_longlong
mm.write_funcs["8 Bytes"] = mm.mem.write_longlong

# Example usage
pointers["New Pointer"] = {
    "Address": 0x11223344,
    "Offsets": [0x70, 0x80],
    "Type": "8 Bytes",
    "Constant": True
}

value = pointers["New Pointer"]["Get"]()
pointers["New Pointer"]["Set"](value + 100)

Dynamic Pointer Calculation

For pointers that require dynamic recalculation (i.e., Constant is False), the Get and Set methods will automatically recalculate the pointer address before performing the read or write operation.

# Read and write dynamic pointers
gold = pointers["Gold"]["Get"]()
pointers["Gold"]["Set"](gold + 500)

Triggers

You can add triggers to monitor changes in memory values and execute callback functions when a change is detected. This is useful for real-time updates and monitoring specific in-game variables.

Adding a Trigger

# Define a callback function for the triggers
def on_value_change(old_value, new_value):
    print(f"Value changed from {old_value} to {new_value}")

# Add a trigger to monitor "Health" every 0.5 seconds
trigger = pointers["Health"]["Triggers"](0.5, on_value_change)

# Main loop (the program could continue doing other things here)
try:
    while True:
        time.sleep(1)  # Simulating the main loop of the program
except KeyboardInterrupt:
    print("Program interrupted.")
    # Remove the trigger when the program ends
    trigger()

Removing a Trigger

The trigger can be removed by calling the function returned when the trigger was added.

# Remove the trigger
trigger()

Acknowledgments

  • pymem - A Python library for process memory manipulation.

This extended example provides a comprehensive guide to using the memory_manager library, including setting up triggers to monitor memory changes dynamically. Adjust the base addresses, offsets, and process/module names as needed for your specific use case.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memory_manager-0.31.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

memory_manager-0.31-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file memory_manager-0.31.tar.gz.

File metadata

  • Download URL: memory_manager-0.31.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for memory_manager-0.31.tar.gz
Algorithm Hash digest
SHA256 8cda00e3e9ddf26d429065c14ceb90933674376684a835c6bb998908db82995f
MD5 d5c23ba61c86ebb79969bbee525bbd65
BLAKE2b-256 7d2b2f1e76fd6fd12e9b6e612b4bd15926070e2d524c0b7b2742fe8c2a137b14

See more details on using hashes here.

File details

Details for the file memory_manager-0.31-py3-none-any.whl.

File metadata

File hashes

Hashes for memory_manager-0.31-py3-none-any.whl
Algorithm Hash digest
SHA256 84b3946bc89752f7335a8660fe641ddcff4ee0b8d70dfa0b21a2f109f9b1cc5b
MD5 2c3073f6b563bc5ab1f4219ab182d96c
BLAKE2b-256 61177de8a07132cbeed68bac7e962425b250047892ce1b04d41ebbfd10f617ec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page