> ## 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

> تعمل hook لـ target function باستخدام replacement function وتعيد cloned copy من original target closure. يجب أن يكون كلا arguments من type functions. تبدأ function بعمل flush لـ pending C function swaps، ثم cloning للـ target عبر function cloning، وتضيف replacement closure أو mapped newcclosure target الخاص بها إلى hidden stack tracking، وتستدعي FixCallstack للـ target و cloned original، ثم تعمل patch للـ target closure عبر C closure أو Luau closure أو newcclosure-specific path. إذا لم يكن target موجودا في hook records، يتم تخزين cloned original هناك من أجل restorefunction. returned function هي cloned original closure.

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

  ## أسماء بديلة

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

  ## الوسائط

  <ParamField path={"target"} type={"function"} required>
    Function المراد patch لها. تمرير non-function يرفع type error.
  </ParamField>

  <ParamField path={"replacement"} type={"function"} required>
    Function التي يتم install أو map للـ function الخاصة بها على target. تمرير non-function يرفع type error.
  </ParamField>

  ## القيم الراجعة

  <ResponseField name={"original"} type={"function"}>
    Cloned copy من original target closure تم إنشاؤها قبل install للـ hook.
  </ResponseField>

  ## مثال

  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>
