Skip to content

Commit f155588

Browse files
committed
Fixed incorrect conversion IGameClient pointer
1 parent 1d17078 commit f155588

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

reapi/src/hook_callback.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void SV_DropClient(IRehldsHook_SV_DropClient *chain, IGameClient *cl, bool crash
2020
{
2121
auto original = [chain](int _cl, bool _crash, const char *_fmt)
2222
{
23-
chain->callNext(g_RehldsSvs->GetClient(_cl - 1), _crash, _fmt);
23+
chain->callNext(clientByIndex(_cl), _crash, _fmt);
2424
};
2525

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

5656
callVoidForward(RH_SV_WriteFullClientUpdate, original, client->GetId() + 1, buffer, receiver ? receiver->GetId() + 1 : AMX_NULLENT);
@@ -87,7 +87,7 @@ void ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* cl)
8787
{
8888
auto original = [chain](int client)
8989
{
90-
chain->callNext(g_RehldsSvs->GetClient(client - 1));
90+
chain->callNext(clientByIndex(client));
9191
};
9292

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

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

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

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

17401740
if (g_RecheckerFuncs->GetResource()->GetPrevHash() == responseHash) {
@@ -1754,7 +1754,7 @@ void FileConsistencyFinal(IRecheckerHook_FileConsistencyFinal *chain, IGameClien
17541754
{
17551755
auto original = [chain](int _cl)
17561756
{
1757-
chain->callNext(g_RehldsSvs->GetClient(_cl - 1));
1757+
chain->callNext(clientByIndex(_cl));
17581758
};
17591759

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

17711771
if (g_RecheckerFuncs->GetResource()->GetPrevHash() == responseHash) {

reapi/src/type_conversion.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#pragma once
22

33
#include <amxxmodule.h>
4+
#include <rehlds_api.h>
45

56
#define INDEXENT edictByIndex
67
#define ENTINDEX indexOfEdict
78
#define AMX_NULLENT -1
89

10+
class IGameClient;
11+
912
extern edict_t* g_pEdicts;
13+
extern IRehldsServerStatic* g_RehldsSvs;
1014

1115
inline size_t indexOfEdict(const edict_t* ed)
1216
{
@@ -41,6 +45,14 @@ inline edict_t* edictByIndex(const int index)
4145
return g_pEdicts + index;
4246
}
4347

48+
inline IGameClient* clientByIndex(const int index)
49+
{
50+
IGameClient* cl = nullptr;
51+
if (likely(index > 0))
52+
cl = g_RehldsSvs->GetClient(index - 1);
53+
return cl;
54+
}
55+
4456
// safe to index -1
4557
inline edict_t* edictByIndexAmx(const int index)
4658
{

0 commit comments

Comments
 (0)