> ## Documentation Index
> Fetch the complete documentation index at: https://www.titanium.bz/llms.txt
> Use this file to discover all available pages before exploring further.

# API Reference

> We expect you to know some basic coding before using these.

## Reflection

### `reflect()`

Built in reflector to find any member, public or non-public.

```csharp theme={null}
dynamic reflect(object? target)
```

**Parameters**

| Name     | Type      | Description                           |
| -------- | --------- | ------------------------------------- |
| `target` | `object?` | Object instance or `Type` to inspect. |

**Returns**

| Type      | Description                                                                                     |
| --------- | ----------------------------------------------------------------------------------------------- |
| `dynamic` | Provides dynamic access to public and non-public fields, properties, methods, and nested types. |

**Example**

```csharp theme={null}
using Sandbox;
using System;

//error due to protection level
dynamic inaccessible = Connection.Local;

try
{
    Log.Info($"HandshakeId = {inaccessible.HandshakeId}");
}
catch (Exception ex)
{
    Log.Warning($"{ex.Message}");
}

// ez bypass
dynamic accessible = reflect(Connection.Local);

try
{
    Log.Info($"HandshakeId = {accessible.HandshakeId}");
}
catch (Exception ex)
{
    Log.Warning($"{ex.Message}");
}
```

Shows the protected `HandshakeId` failing normally, then succeeding through `reflect()`.

***

### `setreadonlyproperty()`

Write into a read-only property.

```csharp theme={null}
object? setreadonlyproperty(object? target, string propertyName, object? value)
```

**Parameters**

| Name           | Type      | Description                              |
| -------------- | --------- | ---------------------------------------- |
| `target`       | `object?` | Object instance containing the property. |
| `propertyName` | `string`  | Name of the property to set.             |
| `value`        | `object?` | Value to write.                          |

**Returns**

| Type      | Description          |
| --------- | -------------------- |
| `object?` | The value passed in. |

**Example**

```csharp theme={null}
using Sandbox;

Log.Info("Before:");
foreach (var c in Connection.All)
    Log.Info($"{c.DisplayName} IsHost={c.IsHost}");

foreach (var c in Connection.All)
    setreadonlyproperty(c, "IsHost", false);

Log.Info("After:");
foreach (var c in Connection.All)
    Log.Info($"{c.DisplayName} IsHost={c.IsHost}");
```

***

## Hooks

Hooks let scripts patch methods using prefix and postfix patch classes, mostly used for replacing a method with a new one.

```csharp theme={null}
public static class MyPatch
{
    public static void Prefix()
    {
        Log.Info("Method was called");
    }
}
```

***

### `hookmethod()`

Hooks a method with a patch class.

```csharp theme={null}
string hookmethod(MethodInfo method, Type patchType)
```

**Parameters**

| Name        | Type         | Description                                                                                      |
| ----------- | ------------ | ------------------------------------------------------------------------------------------------ |
| `method`    | `MethodInfo` | The exact method to hook.                                                                        |
| `patchType` | `Type`       | Class containing static patch methods such as `Prefix`, `Postfix`, `Transpiler`, or `Finalizer`. |

**Returns**

| Type     | Description                                       |
| -------- | ------------------------------------------------- |
| `string` | Status message describing what method was hooked. |

**Example**

```csharp theme={null}
using Sandbox.Diagnostics;
using System.Reflection;

var method = typeof(Logger).GetMethod(
    "Info",
    new[] { typeof(string) }
);

hookmethod(method, typeof(Patch));

new Logger("test").Info("hello");

class Patch
{
    static void Prefix(ref string message)
    {
        message = "xd hooked";
    }
}
```

***

### `unhook()`

Removes hooks created by a specific patch class.

```csharp theme={null}
string unhook(Type patchType)
```

**Parameters**

| Name        | Type   | Description            |
| ----------- | ------ | ---------------------- |
| `patchType` | `Type` | Patch class to remove. |

**Returns**

| Type     | Description                                     |
| -------- | ----------------------------------------------- |
| `string` | Status message confirming the hook was removed. |

**Example**

```csharp theme={null}
unhook(typeof(JumpPatch));
```

***

### `unhookall()`

Removes all Titanium hooks.

```csharp theme={null}
string unhookall()
```

**Returns**

| Type     | Description                                       |
| -------- | ------------------------------------------------- |
| `string` | Status message confirming all hooks were removed. |

**Example**

```csharp theme={null}
unhookall();
```
