Getting Started with ReAPI: Hooks, Natives and Members

November 5, 2025 Daemon666 8 min read 215 просмотров

ReAPI (module reapi) is the modern way to touch CS 1.6 internals from Pawn. Instead of fighting the game through fakemeta offsets and Ham Sandwich guesswork, it gives you named hook chains, named struct members, and high-level natives that do the right thing. The catch is non-negotiable: ReAPI requires ReGameDLL, and most of its hooks require ReHLDS too. A plugin that #include <reapi> will not load on a stock game DLL. Confirm your stack first with regamedll_version in the server console; if that is unknown, install ReGameDLL and ReAPI before writing a line.

1. Hook chains with RegisterHookChain

ReAPI hooks are called hook chains. RegisterHookChain takes a function id, your callback, and a post flag. The function ids are the real ReGameDLL functions, prefixed RG_, and ReHLDS functions prefixed RH_:

#include <amxmodx>
#include <reapi>

public plugin_init()
{
    register_plugin("ReAPI Demo", "1.0", "CSB")

    RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage", 0)
    RegisterHookChain(RG_CBasePlayer_Spawn,      "on_spawn_post", 1)
    RegisterHookChain(RG_RoundEnd,               "on_round_end", 0)
}

As with Ham Sandwich, the post flag chooses pre (0) or post (1). The difference is clarity: the hook name says exactly which game function you are on, and the arguments arrive named and typed.

2. Reading, changing and blocking

Inside a hook, read the arguments as normal parameters. To change an argument, use SetHookChainArg(position, type, value); to change the return value, SetHookChainReturn(type, value). Control flow uses HC_CONTINUE (proceed), HC_SUPERCEDE (block the original), and HC_BREAK:

public on_take_damage(const victim, inflictor, attacker, Float:damage, bits)
{
    if (!is_user_connected(attacker))
        return HC_CONTINUE

    // halve incoming damage, then let the call proceed
    SetHookChainArg(4, ATYPE_FLOAT, damage * 0.5)
    return HC_CONTINUE
}

The ATYPE_* constants tell ReAPI the argument's type: ATYPE_INTEGER, ATYPE_FLOAT, ATYPE_STRING, ATYPE_CLASSPTR, ATYPE_EDICT, ATYPE_EVARS. Match the type to the parameter or the write is ignored.

3. Named members

This is where ReAPI earns its keep. get_member and set_member read and write the player's C++ class fields by name — no offsets, no fakemeta pev tricks:

public give_money(id)
{
    new money = get_member(id, m_iAccount)
    set_member(id, m_iAccount, money + 1000)

    new team = get_member(id, m_iTeam)
    server_print("player %d is on team %d with $%d", id, team, money + 1000)
}

Entity variables (the old entvars_t) have named accessors too, get_entvar/set_entvar, which replace fakemeta's pev/set_pev:

set_entvar(id, var_health, 150.0)
new Float:speed = get_entvar(id, var_maxspeed)

The member and var constant names live in the reapi includes — open them and use the exact identifiers rather than inventing likely-looking ones.

4. High-level natives

ReAPI also ships rg_ natives that wrap common actions correctly, so you do not reconstruct game logic by hand:

rg_add_account(id, 5000)                 // give money (updates HUD)
rg_give_item(id, "weapon_awp")           // give a weapon the proper way
rg_remove_all_items(id, false)           // strip inventory

rg_give_item runs the same path the buy menu uses, so ammo, HUD, and prediction all stay correct — a recurring problem when people fake weapon-giving with raw engine calls. Check the reapi include for the exact native list and argument order.

5. Plugin metadata

When you publish a ReAPI plugin, its metadata must declare the dependency so nobody tries to run it on the wrong stack: set both reapi_required and regamedll_required. The two always travel together — ReAPI's hooks are ReGameDLL's functions.

Common errors

  • Plugin fails to load: reapi module error — the reapi module is not in modules.ini, or ReGameDLL is not installed. Verify with regamedll_version; a stock DLL cannot support ReAPI.
  • SetHookChainArg does nothing — wrong ATYPE_* for the parameter, or you called it in a post hook. Arguments can only be changed in a pre hook.
  • Unknown member constant at compile time — you guessed a member name. The valid m_* and var_* identifiers are in the reapi includes; there is no member that is not defined there.
  • Money/weapon given but HUD wrong — you set m_iAccount directly instead of using rg_add_account, which also refreshes the client. Prefer the rg_ native when one exists.

Verification

Load the plugin on a confirmed ReGameDLL server and check the AMXX log shows it running, not failed. Trigger each hook and confirm a server_print fires with sane named values. For a member write, read it back and confirm it stuck; for rg_add_account, watch the money counter update on the client. If you are weighing ReAPI against the portable alternatives, read register_event vs Hamsandwich vs ReAPI; for raw engine access on non-ReGameDLL servers, fakemeta basics covers the fallback.

Участники: Daemon666 ✦
Поделиться: