Memory Interaction¶
Warning
Please note that memory interaction is currently supported on Windows only. If you wish to contribute to adding MacOS memory interaction, feel free to open a pull request.
gd.py allows to interact with the memory of Geometry Dash.
Quick example of a program that will print a random message every time the player dies.
import random # for fun
import gd
messages = ["Get good.", "RIP", "F", "bruh", "hm..."] # some messages to pick from
# initialize memory object by acquiring process handle and base addresses
memory = gd.memory.get_memory()
do_print = True
while True:
if memory.is_dead(): # if player is dead
if do_print:
print(f"{random.choice(messages)} ({memory.get_percent()}%)")
do_print = False
else:
do_print = True
Types¶
There are several simple types gd.py support for reading/writing memory: Bool, Int32, Int64, Float32, Float64, String.
They can be accessed like so:
import gd
print(gd.memory.Int32)
# or
print(gd.memory.Type.Float64)
Enums¶
-
class
gd.memory.
Scene
(value: Any, names: Union[str, Dict[str, U], List[str], Tuple[str, …]] = (), module: Optional[str] = None, qualname: Optional[str] = None, type: Optional[Type[T]] = None, start: Optional[T] = None, **members: Dict[str, U])[source]¶ An enumeration that represents ID of different scenes in the game.
Buffer¶
-
class
gd.memory.
Buffer
(data: bytes, order: str = 'little')[source]¶ Type that allows to unwrap bytes that were read into different Python types.
-
order
¶ Represents order that buffer should interpret bits in. Either
little
for little-endian orbig
for big-endian.- Type
-
with_order
(order: str) → gd.memory.interface.Buffer[source]¶ Change order of the buffer to
order
and returnself
.
-
classmethod
from_int
(integer: int, size: int = 4, order: str = 'little', signed: bool = True) → gd.memory.interface.Buffer[source]¶ Create buffer from an integer with size and order.
-
classmethod
from_bool
(value: bool, order: str = 'little') → gd.memory.interface.Buffer[source]¶ Create buffer from a boolean with order.
-
as_bool
() → bool[source]¶ Cast current bytes to an integer and return bool indicating if integer is non-zero.
-
classmethod
from_float
(number: float, order: str = 'little') → gd.memory.interface.Buffer[source]¶ Create buffer from a float with order.
float
means 32-bit floating point number.
-
classmethod
from_double
(number: float, order: str = 'little') → gd.memory.interface.Buffer[source]¶ Create buffer from a float with order.
double
means 64-bit floating point number.
-
classmethod
from_str
(string: str, terminate: bool = True, order: str = 'little') → gd.memory.interface.Buffer[source]¶ Create buffer from a string with order. If terminate is
True
, a null byte is appended at the end.
-
as_str
(encoding: str = 'utf-8', errors: str = 'strict') → str[source]¶ Interpret current bytes as a string with encoding, reading until null terminator.
-
classmethod
from_format
(format_str: str) → gd.memory.interface.Buffer[source]¶ Create buffer from byte-format string, like
6A 14 8B CB FF
.
-
Memory API¶
-
class
gd.memory.
WindowsMemory
(process_name: str, load: bool = False, ptr_type: gd.memory.interface.Type = Type<UInt32>(4))[source]¶ -
read_at
(size: int = 0, address: int = 0) → gd.memory.interface.Buffer[source]¶ Read
size
bytes ataddress
, returningBuffer
object.
-
read
(type: gd.memory.interface.Type, address: int = 0) → T[source]¶ Read
type
structure ataddress
, returningBuffer
object.
-
write_at
(buffer: gd.memory.interface.Buffer, address: int = 0) → None[source]¶ Writter
buffer
ataddress
.
-
write
(type: gd.memory.interface.Type, value: T, address: int = 0) → None[source]¶ Write
value
converted totype
ataddress
.
-
read_bytes
(size: int = 0, *offsets, module: Optional[str] = None) → gd.memory.interface.Buffer[source]¶ Read
size
bytes, resolving*offsets
to the final address.
-
read_type
(type: gd.memory.interface.Type, *offsets, module: Optional[str] = None) → T[source]¶ Read
type
, resolving*offsets
to the final address.
-
write_bytes
(buffer: gd.memory.interface.Buffer, *offsets, module: Optional[str] = None) → None[source]¶ Write
buffer
, resolving*offsets
to the final address.
-
write_type
(type: gd.memory.interface.Type, value: T, *offsets, module: Optional[str] = None) → None[source]¶ Write
value
converted totype
, resolving*offsets
to the final address.
-
read_string
(*offsets) → str[source]¶ Read string resolving
*offsets
, handling its size and where it is allocated.
-
reload
() → None[source]¶ Reload memory, fetching process process id, process handle and base address.
-
inject_dll
(path: Union[str, pathlib.Path]) → bool[source]¶ Inject DLL from
path
and check if it was successfully injected.
-
redirect_memory
(size: int, *offsets, address: int = 0) → None[source]¶ Allocate
size
bytes, resolve*offsets
and write new address there.
-
get_scene
() → gd.memory.enums.Scene[source]¶ Get value of current scene and convert it to
Scene
enum.
-
resolution_value
¶ Get value of current resolution.
-
get_resolution
() → Tuple[int, int][source]¶ Get value of current resolution and try to get
(w, h)
tuple,(0, 0)
on fail.
-
resolution
¶ Get value of current resolution and try to get
(w, h)
tuple,(0, 0)
on fail.
-
get_level_id_fast
() → int[source]¶ Quickly read level ID, which is not always accurate for example on official levels.
-
level_id_fast
¶ Quickly read level ID, which is not always accurate for example on official levels.
-
user_name
¶ Get name of the user.
-
level_length
¶ Get length of the level in units.
-
object_count
¶ Get level object count.
-
percent
¶ Get current percentage in the level.
-
x_pos
¶ Get X position of the player.
-
y_pos
¶ Get Y position of the player.
-
get_speed_value
() → float[source]¶ Get value of the speed enum, which can be converted to
gd.api.SpeedConstant
.
-
speed_value
¶ Get value of the speed enum, which can be converted to
gd.api.SpeedConstant
.
-
get_speed
() → gd.api.enums.SpeedConstant[source]¶ Get value of the speed and convert it to
gd.api.SpeedConstant
.
-
set_speed
(speed: Union[float, str, gd.api.enums.SpeedConstant], reverse: bool = False) → None[source]¶ Set value of speed to
speed
. Ifreverse
, negate given speed value.
-
speed
¶ Get value of the speed and convert it to
gd.api.SpeedConstant
.
-
size
¶ Get hitbox size of the player icon.
-
gravity
¶ Get value of gravity in the level. Affects cube only.
-
level_id
¶ Get accurate ID of the level.
-
level_name
¶ Get name of the level.
-
level_creator
¶ Get creator name of the level.
-
editor_level_name
¶ Get level name while in editor.
-
level_stars
¶ Get amount of stars of the level.
-
level_score
¶ Get featured score of the level.
-
level_difficulty_value
¶ Get difficulty value of the level, e.g. 0, 10, etc.
-
get_level_demon_difficulty_value
() → int[source]¶ Get demon difficulty value of the level, e.g. 0, 3, etc.
-
level_demon_difficulty_value
¶ Get demon difficulty value of the level, e.g. 0, 3, etc.
-
get_level_difficulty
() → Union[gd.utils.enums.LevelDifficulty, gd.utils.enums.DemonDifficulty][source]¶ Compute actual level difficulty and return the enum.
-
level_difficulty
¶ Compute actual level difficulty and return the enum.
-
attempts
¶ Get amount of total attempts spent on the level.
-
jumps
¶ Get amount of total jumps spent on the level.
-
normal_percent
¶ Get best record in normal mode.
-
practice_percent
¶ Get best record in practice mode.
-
get_level_type_value
() → int[source]¶ Get value of the level type, which can be converted to
LevelType
.
-
get_level_type
() → gd.api.enums.LevelType[source]¶ Get value of the level type, and convert it to
LevelType
.
-
song_id
¶ Get ID of the song that is used.
-
attempt
¶ Get current attempt number.
-