-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathl4d2_blackscreen_fix.sp
180 lines (142 loc) · 3.95 KB
/
l4d2_blackscreen_fix.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <stringtables_data>
#define Config "data/restrict_strings.cfg"
#define MaxString 128
char g_sItems[8192][PLATFORM_MAX_PATH], g_sRestricted[MaxString][PLATFORM_MAX_PATH];
int g_iItemsTotal;
bool g_bEmpty;
public Plugin myinfo =
{
name = "下载文件黑屏修复",
author = "BHaType & Dragokas",
description = "Fixes blacksreen while file downloading"
};
public void OnPluginStart()
{
RegAdminCmd("sm_get_restricted_strings", CMD_GetStringRestricted, ADMFLAG_ROOT, "Get strings from restrict_strings");
RegAdminCmd("sm_restore_st", CMD_RestoreDownloadables, ADMFLAG_ROOT, "Restore downloadables stringtable items");
HookEvent("player_disconnect", eDiconnect, EventHookMode_Pre);
HookEvent("map_transition", eStart, EventHookMode_Pre);
}
public void OnMapStart()
{
CreateTimer(1.0, Timer_SaveDownloadables, .flags = TIMER_FLAG_NO_MAPCHANGE);
}
public Action Timer_SaveDownloadables(Handle timer)
{
SaveDownloadables();
}
void SaveDownloadables()
{
int iTable = FindStringTable("downloadables");
if(iTable == INVALID_STRING_TABLE)
{
LogError("Cannot find 'downloadables' string table!");
return;
}
g_iItemsTotal = 0;
int iNum = GetStringTableNumStrings(iTable);
for (int i; i < iNum; i++)
{
ReadStringTable(iTable, i, g_sItems[g_iItemsTotal], sizeof(g_sItems[]));
g_iItemsTotal++;
}
PrintToServer("[FixScreen] All strings has been saved and deleted from stringtable");
INetworkStringTable table = INetworkStringTable(iTable);
table.DeleteStrings();
int index = ReadRestrictedFiles();
if ( index != -1 )
for (int i; i <= index; i++)
if ( strlen(g_sRestricted[i]) )
AddFileToDownloadsTable(g_sRestricted[i]);
}
public void eStart(Event event, const char[] name, bool dontBroadcast)
{
if (g_iItemsTotal == 0 || g_bEmpty)
return;
for (int i = 0; i < g_iItemsTotal; i++)
if ( strlen(g_sItems[i]) )
AddFileToDownloadsTable(g_sItems[i]);
PrintToServer("[FixScreen] All strings has been restored to downloadables");
}
public void eDiconnect (Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if ( (client == 0 || !IsFakeClient(client)) && !RealPlayerExist(client) )
CreateTimer(6.3, tPlayers);
}
public Action tPlayers(Handle timer)
{
if ( !RealPlayerExist() )
{
g_bEmpty = true;
INetworkStringTable table = INetworkStringTable(FindStringTable("downloadables"));
table.DeleteStrings();
ReadRestrictedFiles();
}
}
public Action CMD_RestoreDownloadables(int client, int args)
{
if ( g_iItemsTotal == 0 )
{
ReplyToCommand(client, "Cannot restore. Downloadables string table is not saved");
return Plugin_Handled;
}
for (int i; i < g_iItemsTotal; i++)
if ( strlen(g_sItems[i]) )
AddFileToDownloadsTable(g_sItems[i]);
return Plugin_Handled;
}
public Action CMD_GetStringRestricted (int client, int args)
{
int index = ReadRestrictedFiles();
if ( index == -1 )
{
ReplyToCommand(client, "No config \"%s\" has been found", Config);
return Plugin_Handled;
}
for (int i; i <= index; i++)
if ( strlen(g_sRestricted[i]) )
ReplyToCommand(client, "%i. %s", i, g_sRestricted[i]);
return Plugin_Handled;
}
int ReadRestrictedFiles ()
{
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), Config);
if ( FileExists(sPath) )
{
int index;
char szBuffer[MaxString];
File hFile = OpenFile(sPath, "r");
while ( ReadFileLine(hFile, szBuffer, MaxString) )
{
if ( szBuffer[0] != '/' && szBuffer[1] != '/' )
{
TrimString(szBuffer);
Format(g_sRestricted[index], MaxString, "%s", szBuffer);
index++;
}
}
delete hFile;
return index;
}
return -1;
}
bool RealPlayerExist (int iExclude = 0)
{
for (int client = 1; client < MaxClients; client++)
{
if ( client != iExclude && IsClientConnected(client) )
{
if ( !IsFakeClient(client) )
{
return true;
}
}
}
return false;
}