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

# hookfunction

> Melakukan hook pada target function dengan replacement function dan mengembalikan cloned copy dari original target closure. Kedua arguments harus berupa functions. Function pertama melakukan flush pending C function swaps, melakukan cloning target melalui function cloning, menambahkan replacement closure atau mapped newcclosure target miliknya ke hidden stack tracking, memanggil FixCallstack untuk target dan cloned original, lalu melakukan patch target closure melalui C closure, Luau closure, atau newcclosure-specific path. Jika target belum ada di hook records, cloned original disimpan di sana untuk restorefunction. Returned function adalah cloned original closure.

<div className="real-function-page">
  ```lua theme={null}
  hookfunction(target: function, replacement: function): function
  ```

  ## Alias

  * `hookfunc`
  * `replaceclosure`
  * `detourfunction`
  * `detour_function`

  ## Argumen

  <ParamField path={"target"} type={"function"} required>
    Function yang akan di-patch. Mengirim non-function memunculkan type error.
  </ParamField>

  <ParamField path={"replacement"} type={"function"} required>
    Function yang function-nya di-install ke atau di-map pada target. Mengirim non-function memunculkan type error.
  </ParamField>

  ## Return

  <ResponseField name={"original"} type={"function"}>
    Cloned copy dari original target closure yang dibuat sebelum hook di-install.
  </ResponseField>

  ## Contoh

  Patch a function closure and keep a cloned original.

  ```lua theme={null}
  local function target(value)
      return value + 1
  end

  local original
  original = hookfunction(target, function(value)
      return original(value) * 2
  end)
  ```
</div>
