# Hooking

### Clone Function <a href="#clone-function" id="clone-function"></a>

{% code lineNumbers="true" %}

```typescript
<function> clonefunction(<function> a1)
```

{% endcode %}

* Clones function `a1`.

> Alternative: `clonefunc`

***

### Get Callback Value

{% code lineNumbers="true" %}

```typescript
<any> getcallbackvalue(<function fn>)
```

{% endcode %}

* Retrieves the current value or reference of `fn` that has been set or hooked.

***

### Hook Function

{% code lineNumbers="true" %}

```typescript
<function> hookfunction(<function> old, <function> new)  
```

{% endcode %}

* Hooks function `old`, replacing it with the function `new`. The `old` function is returned, you *must* use this function in order to call the original function.

> Alternative: `replaceclosure`, `hookfunc`, `replacefunction`, `replacefunc`, `detourfunction`, `replaceclosure`, `detour_function`

***

### Hook Metamethod

{% code lineNumbers="true" %}

```typescript
<function> hookmetamethod(<Object> object, <string> metamethod, <function> a1)  
```

{% endcode %}

* Hooks the `metamethod` passed in `object`'s metatable with `a1`.

***

### Is Hooked

{% code lineNumbers="true" %}

```typescript
<bool> ishooked(<function fn>)
```

{% endcode %}

* Checks if `fn` has been hooked (i.e., replaced or wrapped by a hook).

> Alternative: `isfunctionhooked`

***

### Is Our Call Stack

{% code lineNumbers="true" %}

```typescript
<bool> isourcallstack(<int level>)
```

{% endcode %}

* Checks the entire callstack to see if it is from Wave or Roblox.

***

### New C Closure

{% code lineNumbers="true" %}

```typescript
<function> newcclosure(<function> a1)  
```

{% endcode %}

* Pushes a new C Closure that invokes the function `a1` upon call.

***

### New Lua Closure

{% code lineNumbers="true" %}

```typescript
<function> newlclosure(<function fn>)
```

{% endcode %}

* Pushes a new L Closure that invokes the function `fn` upon call.

***

### Protect Closure

{% code lineNumbers="true" %}

```typescript
<void> protectclosure(<function fn>)
```

{% endcode %}

* Prevents `fn` from being hooked or modified by external code.

> Alternative: `protectfunction`

***

### Restore Closure

{% code lineNumbers="true" %}

```typescript
<void> restoreclosure(<function fn>)
```

{% endcode %}

* Restores `fn` back to its original, unmodified closure.

> Alternative: `restorefunction`, `restorefunc`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://duckys-playground.gitbook.io/wave/functions/hooking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
