Skip to content

Commit 062a3f7

Browse files
committed
Trying to fix IClient
1 parent f5174b0 commit 062a3f7

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

source/detours.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bool Detours::Function::SetSignOnState(IClient* cl, int state, int spawncount)
2424

2525
bool hook_CBaseClient_SetSignonState(IClient* cl, int state, int spawncount)
2626
{
27-
if (Lua::Hooks::OnSetSignonState(cl->GetPlayerSlot(), state, spawncount))
27+
if (Lua::Hooks::OnSetSignonState(cl, state, spawncount))
2828
return false;
2929

3030
return detour_CBaseClient_SetSignonState.GetTrampoline<CBaseClient_SetSignonState>()(cl, state, spawncount);

source/lua.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
#include "lua.h"
44
#include <GarrysMod/InterfacePointers.hpp>
55
#include "filesystem.h"
6+
#include "unordered_map"
67

78
IServer* Server;
8-
bool Lua::Hooks::OnSetSignonState(int userID, int state, int spawncount) // Return true to block it. You would need to block SIGNONSTATE_PRESPAWN to block it from spawning the player.
9+
int iSlot = 0;
10+
std::unordered_map<int, IClient*> pClients;
11+
bool Lua::Hooks::OnSetSignonState(IClient* cl, int state, int spawncount) // Return true to block it. You would need to block SIGNONSTATE_PRESPAWN to block it from spawning the player.
912
{
1013
if (Lua::PushHook("PlayerQueue:OnSetSignonState"))
1114
{
12-
g_Lua->PushNumber(userID);
15+
++iSlot;
16+
pClients[iSlot] = cl;
17+
18+
g_Lua->PushNumber(iSlot);
1319
g_Lua->PushNumber(state);
1420
g_Lua->PushNumber(spawncount);
1521
if (g_Lua->CallFunctionProtected(4, 1, true)) // Arg1 = Arguments, Arg2 = Returns, Arg3 = Show Error
@@ -29,20 +35,18 @@ bool Lua::Hooks::OnSetSignonState(int userID, int state, int spawncount) // Retu
2935

3036
LUA_FUNCTION_STATIC(SetSignOnState)
3137
{
32-
int playerIndex = LUA->CheckNumber(1);
38+
int playerSlot = LUA->CheckNumber(1);
3339
int state = LUA->CheckNumber(2);
34-
INetChannelInfo* channel = engine->GetPlayerNetInfo(playerIndex);
35-
if ( channel != nullptr ) { // We skip bots and empty slots with this.
36-
IClient* cl = (IClient*)Server->GetClient(playerIndex);
37-
if (cl != NULL)
38-
{
39-
Detours::Function::SetSignOnState(cl, state, -1);
40-
LUA->PushBool(true);
41-
return 1;
42-
}
40+
41+
auto& it = pClients.find(playerSlot);
42+
if ( it == pClients.end() )
43+
{
44+
LUA->PushBool(false);
45+
} else {
46+
Detours::Function::SetSignOnState(it->second, state, -1);
47+
LUA->PushBool(true);
4348
}
4449

45-
LUA->PushBool(false);
4650
return 1;
4751
}
4852

source/lua.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Lua {
77
namespace Hooks {
8-
extern bool OnSetSignonState(int userID, int state, int spawncount);
8+
extern bool OnSetSignonState(IClient* cl, int state, int spawncount);
99
}
1010

1111
extern bool PushHook(const char* pName);

0 commit comments

Comments
 (0)