1

我正在尝试从 DLL 调用位于程序中的函数。

该程序是封闭源代码,但结构是已知的。

我需要调用一个名为“GetPlayerPosition”的函数,如下所示:

// native GetPlayerPos(playerid, &Float:x, &Float:y, &Float:z)
static cell AMX_NATIVE_CALL n_GetPlayerPos(AMX *amx, cell *params)
{
    CHECK_PARAMS(4);

    CPlayer* pPlayer = pNetGame->GetPlayerPool()->GetAt((BYTE)params[1]);

    if (pPlayer)
    {
        cell* cptr;
        amx_GetAddr(amx, params[2], &cptr);
        *cptr = amx_ftoc(pPlayer->m_vecPos.X);
        amx_GetAddr(amx, params[3], &cptr);
        *cptr = amx_ftoc(pPlayer->m_vecPos.Y);
        amx_GetAddr(amx, params[4], &cptr);
        *cptr = amx_ftoc(pPlayer->m_vecPos.Z);

        return 1;
    } else {
        return 0;
    }
}

我想从我的 DLL/SO 调用这部分:

pNetGame->GetPlayerPool()->GetAt((BYTE)<my own input data here>);

我知道结构/类是这样的:

typedef struct _VECTOR {
    float X,Y,Z;
} VECTOR, *PVECTOR;

CNetGame    *pNetGame   = NULL;

class CNetGame
{
private:
    CPlayerPool                 *m_pPlayerPool;
public:
    CNetGame();
    ~CNetGame();
    CPlayerPool * GetPlayerPool() { return m_pPlayerPool; };
};

void CNetGame::Init(BOOL bFirst = false)
{
    // Setup player pool
    if(!m_pPlayerPool) {
        m_pPlayerPool = new CPlayerPool();
    } else {
        m_pPlayerPool->ResetPlayerScoresAndMoney();
    }
}

class CPlayerPool
{
private:

    BOOL    m_bPlayerSlotState[MAX_PLAYERS];
    CPlayer *m_pPlayers[MAX_PLAYERS];

public:

    CPlayerPool();
    ~CPlayerPool();

    BOOL New(BYTE bytePlayerID, PCHAR szPlayerName);
    BOOL Delete(BYTE bytePlayerID, BYTE byteReason);

    // Retrieve a player
    CPlayer* GetAt(BYTE bytePlayerID) {
        if (bytePlayerID >= MAX_PLAYERS) { return NULL; }
        return m_pPlayers[bytePlayerID];
    };
};

class CPlayer
{
private:
    BYTE                    m_bytePlayerID;

public:

    CPlayer();
    ~CPlayer() {};

    VECTOR  m_vecPos;

};

那么我将如何pNetGame->GetPlayerPool()->GetAt((BYTE)<my own input data here>);使用这个设置调用呢?

4

0 回答 0