RecompExternalPython for N64Recompiled 2.0.0
Loading...
Searching...
No Matches

repy_api.mem.byteswapped: This module provides easy reading and writing of data inside N64Recompiled memory. More...

int repy_api.mem.byteswapped.read_u8 (int ptr)
 Read an unsigned, 8-bit integer from recompiled memory and cast it as a Python int type.
 repy_api.mem.byteswapped.write_u8 (int ptr, int value)
 Write a Python int object to recompiled memory as an unsigned 8-bit integer.
int repy_api.mem.byteswapped.read_u16 (int ptr)
 Read an unsigned, 16-bit integer from recompiled memory and cast it as a Python int type.
 repy_api.mem.byteswapped.write_u16 (int ptr, int value)
 Write a Python int object to recompiled memory as an unsigned 16-bit integer.
int repy_api.mem.byteswapped.read_u32 (int ptr)
 Read an unsigned, 32-bit integer from recompiled memory and cast it as a Python int type.
 repy_api.mem.byteswapped.write_u32 (int ptr, int value)
 Write a Python int object to recompiled memory as an unsigned 32-bit integer.
int repy_api.mem.byteswapped.read_u64 (int ptr)
 Read an unsigned, 64-bit integer from recompiled memory and cast it as a Python int type.
 repy_api.mem.byteswapped.write_u64 (int ptr, int value)
 Write a Python int object to recompiled memory as an unsigned 32-bit integer.
int repy_api.mem.byteswapped.read_s8 (int ptr)
 Read a signed, 8-bit integer from recompiled memory and cast it as a Python int type.
 repy_api.mem.byteswapped.write_s8 (int ptr, int value)
 Write a Python int object to recompiled memory as a signed 8-bit integer.
int repy_api.mem.byteswapped.read_s16 (int ptr)
 Read a signed, 16-bit integer from recompiled memory and cast it as a Python int type.
 repy_api.mem.byteswapped.write_s16 (int ptr, int value)
 Write a Python int object to recompiled memory as a signed 16-bit integer.
int repy_api.mem.byteswapped.read_s32 (int ptr)
 Read a signed, 32-bit integer from recompiled memory and cast it as a Python int type.
 repy_api.mem.byteswapped.write_s32 (int ptr, int value)
 Write a Python int object to recompiled memory as a signed 32-bit integer.
int repy_api.mem.byteswapped.read_s64 (int ptr)
 Read a signed, 64-bit integer from recompiled memory and cast it as a Python int type.
 repy_api.mem.byteswapped.write_s64 (int ptr, int value)
 Write a Python int object to recompiled memory as a signed 64-bit integer.
float repy_api.mem.byteswapped.read_f32 (int ptr)
 Read a 32-bit floating point value from recompiled memory and cast it as a Python float type.
 repy_api.mem.byteswapped.write_f32 (int ptr, float value)
 Write a Python float object to recompiled memory as a 32-bit floating point value.
float repy_api.mem.byteswapped.read_f64 (int ptr)
 Read a 64-bit floating point value from recompiled memory and cast it as a Python float type.
 repy_api.mem.byteswapped.write_f64 (int ptr, float value)
 Write a Python float object to recompiled memory as a 64-bit floating point value.
str repy_api.mem.byteswapped.read_char (int ptr)
 Read a single character from recompiled memory and cast it to a Python str object.
 repy_api.mem.byteswapped.write_char (int ptr, str char)
 Write a single character represented by a str object to recompiled memory.
bytes repy_api.mem.byteswapped.read_byte_char (int ptr)
 Read a single character from recompiled memory and cast it to a Python bytes object.
 repy_api.mem.byteswapped.write_byte_char (int ptr, bytes char)
 Write a single character represented by a bytes object to recompiled memory.
str repy_api.mem.byteswapped.read_str (int ptr)
 Read a null-terminated string from recompiled memory and cast it as a Python str object.
str repy_api.mem.byteswapped.read_str_n (int ptr, int size)
 Read a string from recompiled memory and cast it as a Python str object.
 repy_api.mem.byteswapped.write_str_n (int ptr, str data, int size)
 Write a Python str object to recompiled memory as a null-terminated string.
bytes repy_api.mem.byteswapped.read_byte_str (int ptr)
 Read a null-terminated string from recompiled memory and cast it as a Python bytes object.
bytes repy_api.mem.byteswapped.read_byte_str_n (int ptr, int size)
 Read a string from recompiled memory and cast it as a Python bytes object.
 repy_api.mem.byteswapped.write_byte_str_n (int ptr, str data, int size)
 Write a Python bytes object to recompiled memory as a null-terminated string.
bytes repy_api.mem.byteswapped.read_bytes_n (int ptr, int size, bool reverse=False)
 read a region of recompiled memory of size bytes into the Python interpreter as a bytes object.
bytearray repy_api.mem.byteswapped.read_bytearray_n (int ptr, int size, bool reverse=False)
 read a region of recompiled memory of size bytes into the Python interpreter as a bytearray object.
 repy_api.mem.byteswapped.write_buffer_n (int ptr, Buffer data, int size, bool reverse=False)
 Write data from a Python buffer into recompiled memory.

Detailed Description

repy_api.mem.byteswapped: This module provides easy reading and writing of data inside N64Recompiled memory.

Due to the N64 being a big-endian system and most modern machines being little-endian (and more importantly the optimizations that N64Recompiled makes to compensate for this difference, which are beyond the scope of this article), recompiled memory can often appear garbled on the native side, and byteswapping is often necessary when moving data in and out.

The function in this module handle all of that for you, swapping bytes while data is being copied to and from recompiled memory, ensuring that N64Recompiled and Python have the same data in the format they expect. This 'copy and swap' is implemented in C++ for maximum performance. That being said, these are still copy operations. If you need to manipulate recompiled memory directly, look at repy_api.mem.raw.

Note that these functions can only be called from threads created by N64Recompiled. Attempting to call them from other threads (such as threads created with threading.Thread) will throw a RuntimeError. \

Function Documentation

◆ read_byte_char()

bytes repy_api.mem.byteswapped.read_byte_char ( int ptr)

Read a single character from recompiled memory and cast it to a Python bytes object.

Parameters
ptrThe mod memory address to read from.
Returns
a Python str with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_byte_str()

bytes repy_api.mem.byteswapped.read_byte_str ( int ptr)

Read a null-terminated string from recompiled memory and cast it as a Python bytes object.

Parameters
ptrThe mod memory address to read from.
Returns
a Python bytes with the content read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_byte_str_n()

bytes repy_api.mem.byteswapped.read_byte_str_n ( int ptr,
int size )

Read a string from recompiled memory and cast it as a Python bytes object.

Ends with null-termination or when size is reached.

Parameters
ptrThe mod memory address to read from.
sizeThe maximum size of the memory to read.
Returns
a Python bytes with the content read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_bytearray_n()

bytearray repy_api.mem.byteswapped.read_bytearray_n ( int ptr,
int size,
bool reverse = False )

read a region of recompiled memory of size bytes into the Python interpreter as a bytearray object.

Unlike read_byte_str and read_byte_str_n, this function copies the memory region exactly as it is, null bytes and all.

Parameters
ptrThe mod memory address to read from.
sizeThe size of the memory to read.
reverseIf True, mirrors the memory being read. Defaults to False
Returns
a Python bytearray object with the data read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_bytes_n()

bytes repy_api.mem.byteswapped.read_bytes_n ( int ptr,
int size,
bool reverse = False )

read a region of recompiled memory of size bytes into the Python interpreter as a bytes object.

Unlike read_byte_str and read_byte_str_n, this function copies the memory region exactly as it is, null bytes and all.

Parameters
ptrThe mod memory address to read from.
sizeThe size of the memory to read.
reverseIf True, mirrors the memory being read. Defaults to False.
Returns
a Python bytes object with the data read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_char()

str repy_api.mem.byteswapped.read_char ( int ptr)

Read a single character from recompiled memory and cast it to a Python str object.

Parameters
ptrThe mod memory address to read from.
Returns
a Python str with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_f32()

float repy_api.mem.byteswapped.read_f32 ( int ptr)

Read a 32-bit floating point value from recompiled memory and cast it as a Python float type.

Parameters
ptrThe mod memory address to read from.
Returns
a Python float with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_f64()

float repy_api.mem.byteswapped.read_f64 ( int ptr)

Read a 64-bit floating point value from recompiled memory and cast it as a Python float type.

Parameters
ptrThe mod memory address to read from.
Returns
a Python float with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_s16()

int repy_api.mem.byteswapped.read_s16 ( int ptr)

Read a signed, 16-bit integer from recompiled memory and cast it as a Python int type.

Parameters
ptrThe mod memory address to read from.
Returns
a Python int with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_s32()

int repy_api.mem.byteswapped.read_s32 ( int ptr)

Read a signed, 32-bit integer from recompiled memory and cast it as a Python int type.

Parameters
ptrThe mod memory address to read from.
Returns
a Python int with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_s64()

int repy_api.mem.byteswapped.read_s64 ( int ptr)

Read a signed, 64-bit integer from recompiled memory and cast it as a Python int type.

Parameters
ptrThe mod memory address to read from.
Returns
a Python int with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_s8()

int repy_api.mem.byteswapped.read_s8 ( int ptr)

Read a signed, 8-bit integer from recompiled memory and cast it as a Python int type.

Parameters
ptrThe mod memory address to read from.
Returns
a Python int with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_str()

str repy_api.mem.byteswapped.read_str ( int ptr)

Read a null-terminated string from recompiled memory and cast it as a Python str object.

Parameters
ptrThe mod memory address to read from.
Returns
a Python str with the content read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_str_n()

str repy_api.mem.byteswapped.read_str_n ( int ptr,
int size )

Read a string from recompiled memory and cast it as a Python str object.

Ends with null-termination or when size is reached.

Parameters
ptrThe mod memory address to read from.
sizeThe maximum size of the memory to read.
Returns
a Python str with the content read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_u16()

int repy_api.mem.byteswapped.read_u16 ( int ptr)

Read an unsigned, 16-bit integer from recompiled memory and cast it as a Python int type.

Parameters
ptrThe mod memory address to read from.
Returns
a Python int with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_u32()

int repy_api.mem.byteswapped.read_u32 ( int ptr)

Read an unsigned, 32-bit integer from recompiled memory and cast it as a Python int type.

Parameters
ptrThe mod memory address to read from.
Returns
a Python int with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_u64()

int repy_api.mem.byteswapped.read_u64 ( int ptr)

Read an unsigned, 64-bit integer from recompiled memory and cast it as a Python int type.

Parameters
ptrThe mod memory address to read from.
Returns
a Python int with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ read_u8()

int repy_api.mem.byteswapped.read_u8 ( int ptr)

Read an unsigned, 8-bit integer from recompiled memory and cast it as a Python int type.

Parameters
ptrThe mod memory address to read from.
Returns
a Python int with the value read from ptr.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_buffer_n()

repy_api.mem.byteswapped.write_buffer_n ( int ptr,
Buffer data,
int size,
bool reverse = False )

Write data from a Python buffer into recompiled memory.

This function accepts not just bytes and bytearray objects, but any Python type that implements the Python buffer protocol, such as arrays from Python's array module.

If size is greater than the length of data, then writing will be truncated to fit size. If size is less than the length of data, then the remainder of the recompiled memory region will be untouched.

Parameters
ptrThe mod memory address to write to.
dataA Python bytes object to write to mod memory.
sizeThe maximum size of the memory to write.
reverseIf True, mirrors the memory being read. Defaults to False
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_byte_char()

repy_api.mem.byteswapped.write_byte_char ( int ptr,
bytes char )

Write a single character represented by a bytes object to recompiled memory.

Parameters
ptrThe mod memory address to write to.
charThe character to write, expressed as a bytes object.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.
ValueErrorif the length of char is greater than 1.

◆ write_byte_str_n()

repy_api.mem.byteswapped.write_byte_str_n ( int ptr,
str data,
int size )

Write a Python bytes object to recompiled memory as a null-terminated string.

If the bytes object is larger than size, or if the null byte is reached before the end of the bytes object, the content it will be truncated.

Parameters
ptrThe mod memory address to write to.
dataA Python bytes object to write to mod memory.
sizeThe maximum size of the memory to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_char()

repy_api.mem.byteswapped.write_char ( int ptr,
str char )

Write a single character represented by a str object to recompiled memory.

Parameters
ptrThe mod memory address to write to.
charThe character to write, expressed as a str object.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.
ValueErrorif the length of char is greater than 1.

◆ write_f32()

repy_api.mem.byteswapped.write_f32 ( int ptr,
float value )

Write a Python float object to recompiled memory as a 32-bit floating point value.

Parameters
ptrThe mod memory address to write to.
valueThe floating point value to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_f64()

repy_api.mem.byteswapped.write_f64 ( int ptr,
float value )

Write a Python float object to recompiled memory as a 64-bit floating point value.

Parameters
ptrThe mod memory address to write to.
valueThe floating point value to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_s16()

repy_api.mem.byteswapped.write_s16 ( int ptr,
int value )

Write a Python int object to recompiled memory as a signed 16-bit integer.

Parameters
ptrThe mod memory address to write to.
valueThe integer value to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_s32()

repy_api.mem.byteswapped.write_s32 ( int ptr,
int value )

Write a Python int object to recompiled memory as a signed 32-bit integer.

Parameters
ptrThe mod memory address to write to.
valueThe integer value to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_s64()

repy_api.mem.byteswapped.write_s64 ( int ptr,
int value )

Write a Python int object to recompiled memory as a signed 64-bit integer.

Parameters
ptrThe mod memory address to write to.
valueThe integer value to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_s8()

repy_api.mem.byteswapped.write_s8 ( int ptr,
int value )

Write a Python int object to recompiled memory as a signed 8-bit integer.

Parameters
ptrThe mod memory address to write to.
valueThe integer value to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_str_n()

repy_api.mem.byteswapped.write_str_n ( int ptr,
str data,
int size )

Write a Python str object to recompiled memory as a null-terminated string.

If the str object is larger than size, it will be truncated.

Parameters
ptrThe mod memory address to write to.
dataA Python str object to write to mod memory.
sizeThe maximum size of the memory to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_u16()

repy_api.mem.byteswapped.write_u16 ( int ptr,
int value )

Write a Python int object to recompiled memory as an unsigned 16-bit integer.

Parameters
ptrThe mod memory address to write to.
valueThe integer value to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_u32()

repy_api.mem.byteswapped.write_u32 ( int ptr,
int value )

Write a Python int object to recompiled memory as an unsigned 32-bit integer.

Parameters
ptrThe mod memory address to write to.
valueThe integer value to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_u64()

repy_api.mem.byteswapped.write_u64 ( int ptr,
int value )

Write a Python int object to recompiled memory as an unsigned 32-bit integer.

Parameters
ptrThe mod memory address to write to.
valueThe integer value to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.

◆ write_u8()

repy_api.mem.byteswapped.write_u8 ( int ptr,
int value )

Write a Python int object to recompiled memory as an unsigned 8-bit integer.

Parameters
ptrThe mod memory address to write to.
valueThe integer value to write.
Exceptions
RuntimeErrorif called from a thread not created by N64Recompiled.