Skip to content

Commit

Permalink
优化人数破解功能
Browse files Browse the repository at this point in the history
  • Loading branch information
lakwsh committed Aug 15, 2023
1 parent 8d9768f commit 6e0b564
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
### 1.2 最大玩家数(-1~31)
#### `sv_maxplayers <num>`
- 服务器最多能进多少个玩家(设置为-1则不做修改)
- **该cvar为采用延迟加载,不能加入到启动项中**
### 1.3 禁止大厅匹配
#### `sv_force_unreserved <0/1>`(置1为禁止)
- 开启功能会将`sv_allow_lobby_connect_only`的值置0
Expand Down
1 change: 0 additions & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
### 1.2 Maximum number of players (-1~31)
#### `sv_maxplayers <num>`
- The maximum number of players the server can accommodate (set to -1 for no modification).
- **This cvar is loaded with delay and cannot be added to the startup options.**
### 1.3 Prohibit Lobby Matching
#### `sv_force_unreserved <0/1>` (set to 1 to disable)
- Activating this function will set the value of `sv_allow_lobby_connect_only` to 0.
Expand Down
39 changes: 15 additions & 24 deletions l4dtoolz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,12 @@ void *l4dtoolz::set_rate_ptr = NULL;
void *l4dtoolz::set_rate_org = NULL;

void l4dtoolz::OnChangeMax(IConVar *var, const char *pOldValue, float flOldValue){
CHKVAL
if(!slots_ptr){
err_rules:
var->SetValue(-1);
Msg("[L4DToolZ] sv_maxplayers init error\n");
return;
}
if(!rules_max_ptr){
if(!gamerules_ptr || !CHKPTR(*gamerules_ptr, 0x7)) goto err_rules; // malloc
rules_max_ptr = ((uint ****)gamerules_ptr)[0][0][info_idx];
read_signature(rules_max_ptr, max_player_new, rules_max_org);
}
int new_value = ((ConVar *)var)->GetInt();
int old_value = atoi(pOldValue);
if(new_value==old_value) return;
if(new_value<0){
write_signature(rules_max_ptr, rules_max_org);
write_signature(dsp_max_ptr, dsp_max_org);
Expand Down Expand Up @@ -84,22 +76,27 @@ void l4dtoolz::Cookie_f(const CCommand &args){
ConCommand cookie("sv_cookie", l4dtoolz::Cookie_f, "Lobby reservation cookie");

void l4dtoolz::OnSetMaxCl(IConVar *var, const char *pOldValue, float flOldValue){
CHKVAL
if(!maxcl_ptr){
Msg("[L4DToolZ] sv_setmax init error\n");
return;
}
int new_value = ((ConVar *)var)->GetInt();
int old_value = atoi(pOldValue);
if(new_value==old_value) return;
*maxcl_ptr = new_value;
Msg("[L4DToolZ] maxplayers set to %d\n", new_value);
}
ConVar sv_setmax("sv_setmax", "18", 0, "Max clients", true, 18, true, 32, l4dtoolz::OnSetMaxCl);

void l4dtoolz::LevelInit(char const *){
if(!slots_ptr) return;
void l4dtoolz::ServerActivate(edict_t *, int, int){
int slots = sv_maxplayers.GetInt();
if(slots>=0) *slots_ptr = slots;
if(slots>=0 && slots_ptr) *slots_ptr = slots;
if(rules_max_ptr) return;
if(!gamerules_ptr || !CHKPTR(*gamerules_ptr, 0x7)){ // malloc
Msg("[L4DToolZ] sv_maxplayers(rules) init error\n");
return;
}
rules_max_ptr = ((uint ****)gamerules_ptr)[0][0][info_idx];
read_signature(rules_max_ptr, max_player_new, rules_max_org);
if(slots>=0) write_signature(rules_max_ptr, max_player_new);
}

// Linux: float GetTickInterval(void *);
Expand All @@ -122,15 +119,13 @@ int PreAuth(void *, const void *, int, uint64 steamID){
}

void l4dtoolz::OnBypassAuth(IConVar *var, const char *pOldValue, float flOldValue){
CHKVAL
if(!steam3_ptr){
err_bypass:
var->SetValue(0);
Msg("[L4DToolZ] sv_steam_bypass init error\n");
return;
}
int new_value = ((ConVar *)var)->GetInt();
int old_value = atoi(pOldValue);
if(new_value==old_value) return;
unsigned char authreq_new[6] = {0x04, 0x00};
if(!authreq_ptr){
auto gsv = (uint **)steam3_ptr[1];
Expand Down Expand Up @@ -185,14 +180,12 @@ void l4dtoolz::PostAuth(void *, ValidateAuthTicketResponse_t *rsp){
}

void l4dtoolz::OnAntiSharing(IConVar *var, const char *pOldValue, float flOldValue){
CHKVAL
if(!authrsp_ptr){
var->SetValue(0);
Msg("[L4DToolZ] sv_anti_sharing init error\n");
return;
}
int new_value = ((ConVar *)var)->GetInt();
int old_value = atoi(pOldValue);
if(new_value==old_value) return;
if(new_value) *authrsp_ptr = (uint)&PostAuth;
else *authrsp_ptr = authrsp_org;
}
Expand All @@ -204,14 +197,12 @@ void ReplyReservationRequest(void *, void *){
}

void l4dtoolz::OnForceUnreserved(IConVar *var, const char *pOldValue, float flOldValue){
CHKVAL
if(!lobby_req_ptr){
var->SetValue(0);
Msg("[L4DToolZ] sv_force_unreserved init error\n");
return;
}
int new_value = ((ConVar *)var)->GetInt();
int old_value = atoi(pOldValue);
if(new_value==old_value) return;
if(new_value){
write_signature(lobby_req_ptr, lobby_req_new);
icvar->FindVar("sv_allow_lobby_connect_only")->SetValue(0);
Expand Down
10 changes: 7 additions & 3 deletions l4dtoolz.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#define CHKPTR(P, V) (P && !((uint)(P)&V))
#define CMPPTR(P, V, C) (CHKPTR(P, V) && !((uint)P>>24^(uint)C>>24))
#define READCALL(P) ((P+5-1)+*(int *)(P))
#define CHKVAL \
int new_value = ((ConVar *)var)->GetInt(); \
int old_value = atoi(pOldValue); \
if(new_value==old_value) return;

#pragma pack(push, 1)
struct ValidateAuthTicketResponse_t{
Expand All @@ -28,9 +32,9 @@ class l4dtoolz:public IServerPluginCallbacks{
virtual void Unload();
virtual void Pause(){ }
virtual void UnPause(){ }
virtual const char *GetPluginDescription(){ return "L4DToolZ v2.2.4, https://github.com/lakwsh/l4dtoolz"; }
virtual void LevelInit(char const *pMapName);
virtual void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax){ }
virtual const char *GetPluginDescription(){ return "L4DToolZ v2.2.4p1, https://github.com/lakwsh/l4dtoolz"; }
virtual void LevelInit(char const *pMapName){ }
virtual void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
virtual void GameFrame(bool simulating){ }
virtual void LevelShutdown(){ }
virtual void ClientActive(edict_t *pEntity){ }
Expand Down

0 comments on commit 6e0b564

Please sign in to comment.