-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.cpp
More file actions
372 lines (283 loc) · 8.03 KB
/
Copy pathplugin.cpp
File metadata and controls
372 lines (283 loc) · 8.03 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#include <string>
#include <ISvenModAPI.h>
#include <IClientPlugin.h>
#include <IVideoMode.h>
#include <convar.h>
#include <dbg.h>
#include <base_feature.h>
#include "config.h"
#include "game/utils.h"
#include "game/drawing.h"
#include "modules/patches.h"
// Features
#include "features/custom_vote_popup.h"
#include "features/skybox.h"
#include "features/visual.h"
#include "features/chat_colors.h"
#include "features/camhack.h"
static void SaveSoundcache();
extern bool g_bForceFreeze2;
//-----------------------------------------------------------------------------
// SvenMod's plugin
//-----------------------------------------------------------------------------
class CSvenInternal : public IClientPlugin
{
public:
virtual api_version_s GetAPIVersion();
virtual bool Load(CreateInterfaceFn pfnSvenModFactory, ISvenModAPI *pSvenModAPI, IPluginHelpers *pPluginHelpers);
virtual void PostLoad(bool bGlobalLoad);
virtual void Unload(void);
virtual bool Pause(void);
virtual void Unpause(void);
virtual void GameFrame(client_state_t state, double frametime, bool bPostRunCmd);
virtual PLUGIN_RESULT Draw(void);
virtual PLUGIN_RESULT DrawHUD(float time, int intermission);
virtual const char *GetName(void);
virtual const char *GetAuthor(void);
virtual const char *GetVersion(void);
virtual const char *GetDescription(void);
virtual const char *GetURL(void);
virtual const char *GetDate(void);
virtual const char *GetLogTag(void);
private:
void InitFolders(ISvenModAPI *pSvenModAPI);
private:
float m_flPlatTime;
};
CSvenInternal g_SvenInternal;
IClientPlugin *g_pClientPlugin = &g_SvenInternal;
//-----------------------------------------------------------------------------
// Implement plugin methods
//-----------------------------------------------------------------------------
api_version_s CSvenInternal::GetAPIVersion()
{
return SVENMOD_API_VER;
}
bool CSvenInternal::Load(CreateInterfaceFn pfnSvenModFactory, ISvenModAPI *pSvenModAPI, IPluginHelpers *pPluginHelpers)
{
BindApiToGlobals(pSvenModAPI);
InitFolders(pSvenModAPI);
if ( !LoadFeatures() )
{
Warning("[Sven Internal] Failed to initialize one of features\n");
return false;
}
ConVar_Register();
vmode_t *mode = g_pVideoMode->GetCurrentMode();
g_ScreenInfo.width = mode->width;
g_ScreenInfo.height = mode->height;
g_Config.Init();
g_Config.Load();
g_Drawing.Init();
g_Visual.ResetJumpSpeed();
g_pEngineFuncs->ClientCmd("cl_timeout 999999;unbind F1;unbind F2;exec sven_internal.cfg");
m_flPlatTime = g_pEngineFuncs->Sys_FloatTime();
ConColorMsg({ 40, 255, 40, 255 }, "[Sven Internal] Successfully loaded\n");
return true;
}
void CSvenInternal::PostLoad(bool bGlobalLoad)
{
if (bGlobalLoad)
{
}
else
{
}
PostLoadFeatures();
g_CamHack.Init();
}
void CSvenInternal::Unload(void)
{
UnloadFeatures();
ConVar_Unregister();
}
bool CSvenInternal::Pause(void)
{
Warning("[Sven Internal] It is not allowed to pause the plugin\n");
return false;
}
void CSvenInternal::Unpause(void)
{
}
void CSvenInternal::GameFrame(client_state_t state, double frametime, bool bPostRunCmd)
{
if (bPostRunCmd)
{
if (g_pEngineFuncs->Sys_FloatTime() - m_flPlatTime >= 0.5f)
{
g_Config.UpdateConfigs();
m_flPlatTime = g_pEngineFuncs->Sys_FloatTime();
}
}
else
{
if (state >= CLS_CONNECTED)
{
SaveSoundcache();
if (state == CLS_ACTIVE)
{
g_Skybox.Think();
g_ChatColors.Think();
static int wait_frames_TAGS = 0;
wait_frames_TAGS++;
if (wait_frames_TAGS >= 100)
{
if ( !IsTertiaryAttackGlitchInit_Server() )
{
#ifdef PLATFORM_WINDOWS
HMODULE hServerDLL = Sys_GetModuleHandle("server.dll");
#else
HMODULE hServerDLL = Sys_GetModuleHandle("server.so");
#endif
if (hServerDLL)
{
extern void InitTertiaryAttackGlitch_Server(HMODULE hServerDLL);
InitTertiaryAttackGlitch_Server(hServerDLL);
}
}
wait_frames_TAGS = 0;
}
}
else
{
g_bForceFreeze2 = false;
}
}
else
{
g_bForceFreeze2 = false;
}
}
}
PLUGIN_RESULT CSvenInternal::Draw(void)
{
g_Visual.Process();
g_VotePopup.Draw();
return PLUGIN_CONTINUE;
}
PLUGIN_RESULT CSvenInternal::DrawHUD(float time, int intermission)
{
g_Visual.OnHUDRedraw(time);
return PLUGIN_CONTINUE;
}
const char *CSvenInternal::GetName(void)
{
return "Sven Internal";
}
const char *CSvenInternal::GetAuthor(void)
{
return "Sw1ft / void";
}
const char *CSvenInternal::GetVersion(void)
{
return "2.0.13";
}
const char *CSvenInternal::GetDescription(void)
{
return "Provides various cheats and gameplay enhances";
}
const char *CSvenInternal::GetURL(void)
{
return "https://github.com/sw1ft747/sven_internal";
}
const char *CSvenInternal::GetDate(void)
{
return SVENMOD_BUILD_TIMESTAMP;
}
const char *CSvenInternal::GetLogTag(void)
{
return "SVENINT";
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CSvenInternal::InitFolders(ISvenModAPI *pSvenModAPI)
{
std::string sDir = pSvenModAPI->GetBaseDirectory();
#ifdef PLATFORM_WINDOWS
if ( !CreateDirectory((sDir + "\\sven_internal\\").c_str(), NULL) && GetLastError() != ERROR_ALREADY_EXISTS )
{
Warning("[Sven Internal] Failed to create \"../sven_internal/\" directory\n");
}
if ( !CreateDirectory((sDir + "\\sven_internal\\config\\").c_str(), NULL) && GetLastError() != ERROR_ALREADY_EXISTS )
{
Warning("[Sven Internal] Failed to create \"../sven_internal/config/\" directory\n");
}
if ( !CreateDirectory((sDir + "\\sven_internal\\message_spammer\\").c_str(), NULL) && GetLastError() != ERROR_ALREADY_EXISTS )
{
Warning("[Sven Internal] Failed to create \"../sven_internal/message_spammer/\" directory\n");
}
#else
#error Implement Linux equivalent
#endif
sDir.clear();
}
//-----------------------------------------------------------------------------
// Export the plugin's interface
//-----------------------------------------------------------------------------
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CSvenInternal, IClientPlugin, CLIENT_PLUGIN_INTERFACE_VERSION, g_SvenInternal);
//-----------------------------------------------------------------------------
// Weirdo function
//-----------------------------------------------------------------------------
#ifdef PLATFORM_WINDOWS
static void SetFilesAttributes(const char *m_szFdPath, DWORD dwAttribute)
{
HANDLE hFile;
WIN32_FIND_DATAA FileInformation;
char m_szPath[MAX_PATH];
char m_szFolderInitialPath[MAX_PATH];
char wildCard[MAX_PATH] = "\\*.*";
strcpy(m_szPath, m_szFdPath);
strcpy(m_szFolderInitialPath, m_szFdPath);
strcat(m_szFolderInitialPath, wildCard);
hFile = ::FindFirstFileA(m_szFolderInitialPath, &FileInformation);
if (hFile != INVALID_HANDLE_VALUE)
{
do
{
if (FileInformation.cFileName[0] != '.')
{
strcpy(m_szPath, m_szFdPath);
strcat(m_szPath, "\\");
strcat(m_szPath, FileInformation.cFileName);
#pragma warning(push)
#pragma warning(push)
#pragma warning(disable: 26450)
#pragma warning(disable: 4307)
if (!(FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (FileInformation.nFileSizeHigh * (MAXDWORD + 1)) + FileInformation.nFileSizeLow > 0)
{
//it is a file
::SetFileAttributesA(m_szPath, dwAttribute);
}
#pragma warning(pop)
#pragma warning(pop)
}
} while (::FindNextFileA(hFile, &FileInformation) == TRUE);
::FindClose(hFile);
//DWORD dwError = ::GetLastError();
//if (dwError == ERROR_NO_MORE_FILES)
//{
// //Attributes successfully changed
//}
}
}
static int sleep_frames = 0;
static char szSoundcacheDirectory[MAX_PATH] = { 0 };
static void SaveSoundcache()
{
if ( !*szSoundcacheDirectory )
{
_snprintf(szSoundcacheDirectory, MAX_PATH, "%s\\svencoop_downloads\\maps\\soundcache\\", SvenModAPI()->GetBaseDirectory());
}
if (g_Config.cvars.save_soundcache)
{
sleep_frames++;
if (sleep_frames >= 75)
{
SetFilesAttributes(szSoundcacheDirectory, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_READONLY);
sleep_frames = 0;
}
}
}
#else
#error Implement Linux equivalent
#endif