AGraber / pawn-plus-hooks

Macro helpers for public and native function hooking
4 stars 2 forks source link

Hook Get natives #1

Open fl0w3rs opened 4 years ago

fl0w3rs commented 4 years ago

For example, I need to hook GetPlayerPos native to replace the return value (not quite return, but I think you got the point). How can I do this?

I've already tried

#include <pp-hooks>
hook native GetPlayerPos(playerid, &Float:x, &Float:y, &Float:z) {
    if(admin[playerid][admin_invisible]) {
        x = admin[playerid][admin_real_pos][0];
        y = admin[playerid][admin_real_pos][1];
        z = admin[playerid][admin_real_pos][2];
        return true;
    }
    return GetPlayerPos(playerid, x, y, z);
}

But it brokes SpawnPlayer like there -> https://github.com/IllidanS4/PawnPlus/issues/39

fl0w3rs commented 4 years ago
hook native GetPlayerPos(playerid, &Float:x, &Float:y, &Float:z) {
    return GetPlayerPos(playerid, x, y, z);
}

With this (upper) doesn't work too, but with example (below) it perfectly works

hook native SetPlayerPos(playerid, Float:x, Float:y, Float:z)
{
    // Not recursive: calls next hook or the native
    return SetPlayerPos(playerid, x, y, z + 1.0);
}
ADRFranklin commented 4 years ago

Could you explain in more detail, why this doesn't work? Like what are you expecting it to do, and what are you getting instead?

fl0w3rs commented 4 years ago

Could you explain in more detail, why this doesn't work? Like what are you expecting it to do, and what are you getting instead?

With Pawn.RakNet I made invisibility for administration (z coordinate = 6666). In admin[playerid][admin_real_pos][0-2] their real coordinates are written. I hook GetPlayerPos to replace the player's position if he is invisible. In return I get a broken server.

fl0w3rs commented 4 years ago

This time everything is a little different. I use mdialog, the dialog is created but the response is not called. https://pastebin.com/VV8yxMm6 image