> For the complete documentation index, see [llms.txt](https://docs.anvil.team/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.anvil.team/namespaces/memory.md).

# memory

Lets you read and write memory.

### Methods

* [readFloat](#memory.readfloat-address)
* [writeFloat](#memory.writefloat-address-value)
* [readInt](#memory.readint-address)
* [writeInt](#memory.writeint-address-value)
* [readBytes](#memory.readbytes-address-count)
* [writeBytes](#memory.writebytes-address-bytes)
* [findSignature](#memory.findsignature-pattern-module)

### <mark style="color:green;">`memory.readFloat(address)`</mark>

* <mark style="color:purple;">`address`</mark> - The address you want to read from

Returns the value of the float at the given address.

**Example:**

```lua
local yaw = memory.readFloat(0x00C84FDC)
print(string.format("Value at 0x00C84FDC -> %.2f", yaw))
```

### <mark style="color:green;">`memory.writeFloat(address, value)`</mark>

* <mark style="color:purple;">`address`</mark> - The address you want to write to
* <mark style="color:purple;">`value`</mark> - The value you want to write

Writes the value at the given address.

**Example:**

```lua
memory.writeFloat(0x00C84FDC, 90.0) --write 90 to yaw address
```

### <mark style="color:green;">`memory.readInt(address)`</mark>

* <mark style="color:purple;">`address`</mark> - The address you want to read from

Returns the value of the int at the given address.

**Example:**

```lua
local something = memory.readInt(0x400050)
```

### <mark style="color:green;">`memory.writeInt(address, value)`</mark>

* <mark style="color:purple;">`address`</mark> - The address you want to write to
* <mark style="color:purple;">`value`</mark> - The value you want to write

Writes the value at the given address.

**Example:**

```lua
memory.writeInt(0xFFFFFF, 120)
```

### <mark style="color:green;">`memory.readBytes(address, count)`</mark>

* <mark style="color:purple;">`address`</mark> - The address you want to write to
* <mark style="color:purple;">`value`</mark> - The value you want to write

Reads an amount of bytes specified by count from the given address.\
Will return a list of bytes.

**Example:**

```lua
local bytes = memory.readBytes(0x40EBB0, 7)
-- Returns {0x83, 0xEC, 0x20, 0xF6, 0x47, 0x0C, 0x08
```

### <mark style="color:green;">`memory.writeBytes(address, bytes)`</mark>

* <mark style="color:purple;">`address`</mark> - The address you want to write the bytes to
* <mark style="color:purple;">`bytes`</mark> - The byes you want to write

Writes the given bytes to the address. Page protection is taken care of for you.

**Example:**

```lua
local bytes = {0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90}
local bytes = memory.writeBytes(0x457D29, bytes)
-- Recoil is now patched, giving us norecoil
```

### <mark style="color:green;">`memory.findSignature(pattern, [module])`</mark>

* <mark style="color:purple;">`pattern`</mark> - The byte pattern to try to find. <mark style="color:blue;">Wildcards</mark> in the form of <mark style="color:blue;">?</mark> are allowed.
* <mark style="color:purple;">`module`</mark> - The module in which to search by name. <mark style="color:yellow;">Optional. Defaults to iw3mp.exe!</mark>

Try find the given byte pattern and returns the address if found, 0 otherwise.

**Example:**

```lua
local signature = "8B ? ? ? ? ? ? ? 8B ? ? ? ? E8 ? ? ? ? 83 ? ? F7 ? ? ? ? ? ?"
local pmovesingle = memory.findSignature(signature)
print(string.format("PmoveSingle @ 0x%X", pmovesingle))
-- Prints the address of the pmovesingle engine function
```
