Skip to content

Commit

Permalink
Fixed incorrect conversion IGameClient pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed Dec 12, 2023
1 parent 1d17078 commit f155588
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
18 changes: 9 additions & 9 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void SV_DropClient(IRehldsHook_SV_DropClient *chain, IGameClient *cl, bool crash
{
auto original = [chain](int _cl, bool _crash, const char *_fmt)
{
chain->callNext(g_RehldsSvs->GetClient(_cl - 1), _crash, _fmt);
chain->callNext(clientByIndex(_cl), _crash, _fmt);
};

callVoidForward(RH_SV_DropClient, original, cl->GetId() + 1, crash, fmt);
Expand Down Expand Up @@ -50,7 +50,7 @@ void SV_WriteFullClientUpdate_AMXX(SV_WriteFullClientUpdate_t *data, IGameClient
{
auto original = [data](int _client, size_t _buffer, int _receiver)
{
data->m_chain->callNext(g_RehldsSvs->GetClient(_client - 1), (char *)_buffer, data->m_args.maxlen, data->m_args.message, g_RehldsSvs->GetClient(_receiver - 1));
data->m_chain->callNext(clientByIndex(_client), (char *)_buffer, data->m_args.maxlen, data->m_args.message, clientByIndex(_receiver));
};

callVoidForward(RH_SV_WriteFullClientUpdate, original, client->GetId() + 1, buffer, receiver ? receiver->GetId() + 1 : AMX_NULLENT);
Expand Down Expand Up @@ -87,7 +87,7 @@ void ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* cl)
{
auto original = [chain](int client)
{
chain->callNext(g_RehldsSvs->GetClient(client - 1));
chain->callNext(clientByIndex(client));
};

callVoidForward(RH_ClientConnected, original, cl->GetId() + 1);
Expand All @@ -107,7 +107,7 @@ void SV_EmitPings_AMXX(SV_EmitPings_t* data, IGameClient* cl)
{
auto original = [data](int _cl)
{
data->m_chain->callNext(g_RehldsSvs->GetClient(_cl - 1), data->m_args.message);
data->m_chain->callNext(clientByIndex(_cl), data->m_args.message);
};

callVoidForward(RH_SV_EmitPings, original, cl->GetId() + 1);
Expand Down Expand Up @@ -236,10 +236,10 @@ void ExecuteServerStringCmd(IRehldsHook_ExecuteServerStringCmd* chain, const cha
{
auto original = [chain](const char* _cmdName, cmd_source_t _cmdSrc, int client)
{
chain->callNext(_cmdName, _cmdSrc, _cmdSrc == src_client ? g_RehldsSvs->GetClient(client) - 1 : 0);
chain->callNext(_cmdName, _cmdSrc, _cmdSrc == src_client ? clientByIndex(client) : nullptr);
};

callVoidForward(RH_ExecuteServerStringCmd, original, cmdName, cmdSrc, cmdSrc == src_client ? cl->GetId() + 1 : 0);
callVoidForward(RH_ExecuteServerStringCmd, original, cmdName, cmdSrc, cmdSrc == src_client ? cl->GetId() + 1 : AMX_NULLENT);
}

/*
Expand Down Expand Up @@ -1734,7 +1734,7 @@ void FileConsistencyProcess_AMXX(FileConsistencyProcess_t *data, IGameClient *cl
int hashCopy = responseHash;
auto original = [data, hashCopy](int _cl, const char *_filename, const char *_cmd, ResourceType_e _type, uint32 _hash, bool _isBreak)
{
data->m_chain->callNext(g_RehldsSvs->GetClient(_cl - 1), data->m_args, _type, hashCopy);
data->m_chain->callNext(clientByIndex(_cl), data->m_args, _type, hashCopy);
};

if (g_RecheckerFuncs->GetResource()->GetPrevHash() == responseHash) {
Expand All @@ -1754,7 +1754,7 @@ void FileConsistencyFinal(IRecheckerHook_FileConsistencyFinal *chain, IGameClien
{
auto original = [chain](int _cl)
{
chain->callNext(g_RehldsSvs->GetClient(_cl - 1));
chain->callNext(clientByIndex(_cl));
};

callVoidForward(RC_FileConsistencyFinal, original, cl->GetId() + 1);
Expand All @@ -1765,7 +1765,7 @@ void CmdExec_AMXX(CmdExec_t *data, IGameClient *cl, const char *filename, char *
int hashCopy = responseHash;
auto original = [data, hashCopy](int _cl, const char *_filename, char *_cmd, uint32 _responseHash)
{
data->m_chain->callNext(g_RehldsSvs->GetClient(_cl - 1), data->m_args, _cmd, hashCopy);
data->m_chain->callNext(clientByIndex(_cl), data->m_args, _cmd, hashCopy);
};

if (g_RecheckerFuncs->GetResource()->GetPrevHash() == responseHash) {
Expand Down
12 changes: 12 additions & 0 deletions reapi/src/type_conversion.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#pragma once

#include <amxxmodule.h>
#include <rehlds_api.h>

#define INDEXENT edictByIndex
#define ENTINDEX indexOfEdict
#define AMX_NULLENT -1

class IGameClient;

extern edict_t* g_pEdicts;
extern IRehldsServerStatic* g_RehldsSvs;

inline size_t indexOfEdict(const edict_t* ed)
{
Expand Down Expand Up @@ -41,6 +45,14 @@ inline edict_t* edictByIndex(const int index)
return g_pEdicts + index;
}

inline IGameClient* clientByIndex(const int index)
{
IGameClient* cl = nullptr;
if (likely(index > 0))
cl = g_RehldsSvs->GetClient(index - 1);
return cl;
}

// safe to index -1
inline edict_t* edictByIndexAmx(const int index)
{
Expand Down

0 comments on commit f155588

Please sign in to comment.