-
-
Notifications
You must be signed in to change notification settings - Fork 438
/
Copy pathlogic_bridge.cpp
796 lines (723 loc) · 21.2 KB
/
logic_bridge.cpp
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
/**
* vim: set ts=4 sw=4 tw=99 noet:
* =============================================================================
* SourceMod
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#include <stdio.h>
#include <assert.h>
#include "sourcemod.h"
#include "sourcemm_api.h"
#include "sm_globals.h"
#include "sm_autonatives.h"
#include "sm_stringutil.h"
#include "Logger.h"
#include "TimerSys.h"
#include "logic_bridge.h"
#include "PlayerManager.h"
#include "HalfLife2.h"
#include "MenuManager.h"
#include "CoreConfig.h"
#include "ConCmdManager.h"
#include "IDBDriver.h"
#include "provider.h"
#include "sm_convar.h"
#include <amtl/os/am-shared-library.h>
#include <amtl/os/am-path.h>
#include <bridge/include/IVEngineServerBridge.h>
#include <bridge/include/IPlayerInfoBridge.h>
#include <bridge/include/IFileSystemBridge.h>
sm_logic_t logicore;
IThreader *g_pThreader = nullptr;
ITextParsers *textparsers = nullptr;
ITranslator *translator = nullptr;
IScriptManager *scripts = nullptr;
IShareSys *sharesys = nullptr;
IExtensionSys *extsys = nullptr;
IHandleSys *handlesys = nullptr;
IForwardManager *forwardsys = nullptr;
IAdminSystem *adminsys = nullptr;
ILogger *logger = nullptr;
IRootConsole *rootmenu = nullptr;
class VEngineServer_Logic : public IVEngineServerBridge
{
public:
virtual bool IsDedicatedServer()
{
return engine->IsDedicatedServer();
}
virtual void InsertServerCommand(const char *cmd)
{
engine->InsertServerCommand(cmd);
}
virtual void ServerCommand(const char *cmd)
{
engine->ServerCommand(cmd);
}
virtual void ServerExecute()
{
engine->ServerExecute();
}
virtual const char *GetClientConVarValue(int clientIndex, const char *name)
{
return engine->GetClientConVarValue(clientIndex, name);
}
virtual void ClientCommand(edict_t *pEdict, const char *szCommand)
{
engine->ClientCommand(pEdict, "%s", szCommand);
}
virtual void FakeClientCommand(edict_t *pEdict, const char *szCommand)
{
serverpluginhelpers->ClientCommand(pEdict, szCommand);
}
} engine_wrapper;
class VFileSystem_Logic : public IFileSystemBridge
{
public:
const char *FindFirstEx(const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle) override
{
return filesystem->FindFirstEx(pWildCard, pPathID, pHandle);
}
const char *FindNext(FileFindHandle_t handle) override
{
return filesystem->FindNext(handle);
}
bool FindIsDirectory(FileFindHandle_t handle) override
{
return filesystem->FindIsDirectory(handle);
}
void FindClose(FileFindHandle_t handle) override
{
filesystem->FindClose(handle);
}
FileHandle_t Open(const char *pFileName, const char *pOptions, const char *pathID = 0) override
{
return filesystem->Open(pFileName, pOptions, pathID);
}
void Close(FileHandle_t file) override
{
filesystem->Close(file);
}
char *ReadLine(char *pOutput, int maxChars, FileHandle_t file) override
{
return filesystem->ReadLine(pOutput, maxChars, file);
}
bool EndOfFile(FileHandle_t file) override
{
return filesystem->EndOfFile(file);
}
bool FileExists(const char *pFileName, const char *pPathID = 0) override
{
return filesystem->FileExists(pFileName, pPathID);
}
unsigned int Size(FileHandle_t file) override
{
return filesystem->Size(file);
}
unsigned int Size(const char *pFileName, const char *pPathID = 0) override
{
return filesystem->Size(pFileName, pPathID);
}
int Read(void* pOutput, int size, FileHandle_t file) override
{
return filesystem->Read(pOutput, size, file);
}
int Write(void const* pInput, int size, FileHandle_t file) override
{
return filesystem->Write(pInput, size, file);
}
void Seek(FileHandle_t file, int pos, int seekType) override
{
filesystem->Seek(file, pos, (FileSystemSeek_t) seekType);
}
unsigned int Tell(FileHandle_t file) override
{
return filesystem->Tell(file);
}
int FPrint(FileHandle_t file, const char *pData) override
{
return filesystem->FPrintf(file, "%s", pData);
}
void Flush(FileHandle_t file) override
{
filesystem->Flush(file);
}
bool IsOk(FileHandle_t file) override
{
return filesystem->IsOk(file);
}
void RemoveFile(const char *pRelativePath, const char *pathID) override
{
filesystem->RemoveFile(pRelativePath, pathID);
}
void RenameFile(char const *pOldPath, char const *pNewPath, const char *pathID) override
{
filesystem->RenameFile(pOldPath, pNewPath, pathID);
}
bool IsDirectory(const char *pFileName, const char *pathID) override
{
return filesystem->IsDirectory(pFileName, pathID);
}
void CreateDirHierarchy(const char *path, const char *pathID) override
{
filesystem->CreateDirHierarchy(path, pathID);
}
int GetSearchPath(const char* pathID, bool bGetPackFiles, char* pPath, int nMaxLen) override
{
return filesystem->GetSearchPath(pathID, bGetPackFiles, pPath, nMaxLen);
}
} fs_wrapper;
class VPlayerInfo_Logic : public IPlayerInfoBridge
{
public:
bool IsObserver(IPlayerInfo *pInfo)
{
return pInfo->IsObserver();
}
int GetTeamIndex(IPlayerInfo *pInfo)
{
return pInfo->GetTeamIndex();
}
int GetFragCount(IPlayerInfo *pInfo)
{
return pInfo->GetFragCount();
}
int GetDeathCount(IPlayerInfo *pInfo)
{
return pInfo->GetDeathCount();
}
int GetArmorValue(IPlayerInfo *pInfo)
{
return pInfo->GetArmorValue();
}
void GetAbsOrigin(IPlayerInfo *pInfo, float *x, float *y, float *z)
{
Vector vec = pInfo->GetAbsOrigin();
*x = vec.x;
*y = vec.y;
*z = vec.z;
}
void GetAbsAngles(IPlayerInfo *pInfo, float *x, float *y, float *z)
{
QAngle ang = pInfo->GetAbsAngles();
*x = ang.x;
*y = ang.y;
*z = ang.z;
}
void GetPlayerMins(IPlayerInfo *pInfo, float *x, float *y, float *z)
{
Vector vec = pInfo->GetPlayerMins();
*x = vec.x;
*y = vec.y;
*z = vec.z;
}
void GetPlayerMaxs(IPlayerInfo *pInfo, float *x, float *y, float *z)
{
Vector vec = pInfo->GetPlayerMaxs();
*x = vec.x;
*y = vec.y;
*z = vec.z;
}
const char *GetWeaponName(IPlayerInfo *pInfo)
{
return pInfo->GetWeaponName();
}
const char *GetModelName(IPlayerInfo *pInfo)
{
return pInfo->GetModelName();
}
int GetHealth(IPlayerInfo *pInfo)
{
return pInfo->GetHealth();
}
void ChangeTeam(IPlayerInfo *pInfo, int iTeamNum)
{
pInfo->ChangeTeam(iTeamNum);
}
} playerinfo_wrapper;
static ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY, "Activity display setting (see sourcemod.cfg)");
static ConVar sm_immunity_mode("sm_immunity_mode", "1", FCVAR_SPONLY, "Mode for deciding immunity protection");
static ConVar sm_datetime_format("sm_datetime_format", "%m/%d/%Y - %H:%M:%S", 0, "Default formatting time rules");
static const char* get_core_config_value(const char* key)
{
return g_CoreConfig.GetCoreConfigValue(key);
}
static void keyvalues_to_dbinfo(KeyValues *kv, DatabaseInfo *out)
{
out->database = kv->GetString("database", "");
out->driver = kv->GetString("driver", "default");
out->host = kv->GetString("host", "");
out->maxTimeout = kv->GetInt("timeout", 0);
out->pass = kv->GetString("pass", "");
out->port = kv->GetInt("port", 0);
out->user = kv->GetString("user", "");
}
static int get_activity_flags()
{
return sm_show_activity.GetInt();
}
static int get_immunity_mode()
{
return sm_immunity_mode.GetInt();
}
static void update_admin_cmd_flags(const char *cmd, OverrideType type, FlagBits bits, bool remove)
{
g_ConCmds.UpdateAdminCmdFlags(cmd, type, bits, remove);
}
static bool look_for_cmd_admin_flags(const char *cmd, FlagBits *pFlags)
{
return g_ConCmds.LookForCommandAdminFlags(cmd, pFlags);
}
void do_global_plugin_loads()
{
g_SourceMod.DoGlobalPluginLoads();
}
static int get_global_target()
{
return g_SourceMod.GetGlobalTarget();
}
void UTIL_ConsolePrintVa(const char *fmt, va_list ap)
{
char buffer[512];
size_t len = ke::SafeVsprintf(buffer, sizeof(buffer), fmt, ap);
if (len >= sizeof(buffer) - 1)
{
buffer[510] = '\n';
buffer[511] = '\0';
} else {
buffer[len++] = '\n';
buffer[len] = '\0';
}
META_CONPRINT(buffer);
}
void UTIL_ConsolePrint(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
UTIL_ConsolePrintVa(fmt, ap);
va_end(ap);
}
#if SOURCE_ENGINE == SE_LEFT4DEAD
#define GAMEFIX "2.l4d"
#elif SOURCE_ENGINE == SE_LEFT4DEAD2
#define GAMEFIX "2.l4d2"
#elif SOURCE_ENGINE == SE_NUCLEARDAWN
#define GAMEFIX "2.nd"
#elif SOURCE_ENGINE == SE_ALIENSWARM
#define GAMEFIX "2.swarm"
#elif SOURCE_ENGINE == SE_ORANGEBOX
#define GAMEFIX "2.ep2"
#elif SOURCE_ENGINE == SE_BLOODYGOODTIME
#define GAMEFIX "2.bgt"
#elif SOURCE_ENGINE == SE_EYE
#define GAMEFIX "2.eye"
#elif SOURCE_ENGINE == SE_CSS
#define GAMEFIX "2.css"
#elif SOURCE_ENGINE == SE_HL2DM
#define GAMEFIX "2.hl2dm"
#elif SOURCE_ENGINE == SE_DODS
#define GAMEFIX "2.dods"
#elif SOURCE_ENGINE == SE_SDK2013
#define GAMEFIX "2.sdk2013"
#elif SOURCE_ENGINE == SE_BMS
#define GAMEFIX "2.bms"
#elif SOURCE_ENGINE == SE_TF2
#define GAMEFIX "2.tf2"
#elif SOURCE_ENGINE == SE_DARKMESSIAH
#define GAMEFIX "2.darkm"
#elif SOURCE_ENGINE == SE_PORTAL2
#define GAMEFIX "2.portal2"
#elif SOURCE_ENGINE == SE_BLADE
#define GAMEFIX "2.blade"
#elif SOURCE_ENGINE == SE_INSURGENCY
#define GAMEFIX "2.insurgency"
#elif SOURCE_ENGINE == SE_DOI
#define GAMEFIX "2.doi"
#elif SOURCE_ENGINE == SE_CSGO
#define GAMEFIX "2.csgo"
#elif SOURCE_ENGINE == SE_CONTAGION
#define GAMEFIX "2.contagion"
#elif SOURCE_ENGINE == SE_PVKII
#define GAMEFIX "2.pvkii"
#elif SOURCE_ENGINE == SE_MCV
#define GAMEFIX "2.mcv"
#elif SOURCE_ENGINE == SE_MOCK
#define GAMEFIX "2.mock"
#else
#define GAMEFIX "2.ep1"
#endif
static ServerGlobals serverGlobals;
CoreProviderImpl sCoreProviderImpl;
CoreProviderImpl::CoreProviderImpl()
{
this->sm = &g_SourceMod;
this->engine = &engine_wrapper;
this->filesystem = &fs_wrapper;
this->playerInfo = &playerinfo_wrapper;
this->timersys = &g_Timers;
this->playerhelpers = &g_Players;
this->gamehelpers = &g_HL2;
this->menus = &g_Menus;
this->spe1 = &g_pSourcePawn;
this->spe2 = &g_pSourcePawn2;
this->GetCoreConfigValue = get_core_config_value;
this->DoGlobalPluginLoads = do_global_plugin_loads;
this->AreConfigsExecuted = SM_AreConfigsExecuted;
this->ExecuteConfigs = SM_ExecuteForPlugin;
this->GetDBInfoFromKeyValues = keyvalues_to_dbinfo;
this->GetActivityFlags = get_activity_flags;
this->GetImmunityMode = get_immunity_mode;
this->UpdateAdminCmdFlags = update_admin_cmd_flags;
this->LookForCommandAdminFlags = look_for_cmd_admin_flags;
this->GetGlobalTarget = get_global_target;
this->gamesuffix = GAMEFIX;
this->serverGlobals = &::serverGlobals;
this->listeners = nullptr;
}
ConVar *CoreProviderImpl::FindConVar(const char *name)
{
return icvar->FindVar(name);
}
const char *CoreProviderImpl::GetCvarString(ConVar* cvar)
{
return cvar->GetString();
}
bool CoreProviderImpl::GetCvarBool(ConVar* cvar)
{
return cvar->GetBool();
}
bool CoreProviderImpl::GetGameName(char *buffer, size_t maxlength)
{
KeyValues *pGameInfo = new KeyValues("GameInfo");
if (g_HL2.KVLoadFromFile(pGameInfo, basefilesystem, "gameinfo.txt"))
{
const char *str;
if ((str = pGameInfo->GetString("game", NULL)) != NULL)
{
ke::SafeStrcpy(buffer, maxlength, str);
pGameInfo->deleteThis();
return true;
}
}
pGameInfo->deleteThis();
return false;
}
const char *CoreProviderImpl::GetGameDescription()
{
return SERVER_CALL(GetGameDescription)();
}
const char *CoreProviderImpl::GetSourceEngineName()
{
#if !defined SOURCE_ENGINE
# error "Unknown engine type"
#endif
#if SOURCE_ENGINE == SE_EPISODEONE
return "original";
#elif SOURCE_ENGINE == SE_DARKMESSIAH
return "darkmessiah";
#elif SOURCE_ENGINE == SE_ORANGEBOX
return "orangebox";
#elif SOURCE_ENGINE == SE_BLOODYGOODTIME
return "bloodygoodtime";
#elif SOURCE_ENGINE == SE_EYE
return "eye";
#elif SOURCE_ENGINE == SE_CSS
return "css";
#elif SOURCE_ENGINE == SE_HL2DM
return "hl2dm";
#elif SOURCE_ENGINE == SE_DODS
return "dods";
#elif SOURCE_ENGINE == SE_SDK2013
return "sdk2013";
#elif SOURCE_ENGINE == SE_BMS
return "bms";
#elif SOURCE_ENGINE == SE_TF2
return "tf2";
#elif SOURCE_ENGINE == SE_LEFT4DEAD
return "left4dead";
#elif SOURCE_ENGINE == SE_NUCLEARDAWN
return "nucleardawn";
#elif SOURCE_ENGINE == SE_CONTAGION
return "contagion";
#elif SOURCE_ENGINE == SE_LEFT4DEAD2
return "left4dead2";
#elif SOURCE_ENGINE == SE_ALIENSWARM
return "alienswarm";
#elif SOURCE_ENGINE == SE_PORTAL2
return "portal2";
#elif SOURCE_ENGINE == SE_BLADE
return "blade";
#elif SOURCE_ENGINE == SE_INSURGENCY
return "insurgency";
#elif SOURCE_ENGINE == SE_DOI
return "doi";
#elif SOURCE_ENGINE == SE_CSGO
return "csgo";
#elif SOURCE_ENGINE == SE_MOCK
return "mock";
#elif SOURCE_ENGINE == SE_PVKII
return "pvkii";
#elif SOURCE_ENGINE == SE_MCV
return "mcv";
#endif
}
bool CoreProviderImpl::SymbolsAreHidden()
{
#if (SOURCE_ENGINE == SE_CSS) \
|| (SOURCE_ENGINE == SE_HL2DM) \
|| (SOURCE_ENGINE == SE_DODS) \
|| (SOURCE_ENGINE == SE_SDK2013) \
|| (SOURCE_ENGINE == SE_BMS) \
|| (SOURCE_ENGINE == SE_TF2) \
|| (SOURCE_ENGINE == SE_LEFT4DEAD) \
|| (SOURCE_ENGINE == SE_NUCLEARDAWN) \
|| (SOURCE_ENGINE == SE_LEFT4DEAD2) \
|| (SOURCE_ENGINE == SE_INSURGENCY) \
|| (SOURCE_ENGINE == SE_DOI) \
|| (SOURCE_ENGINE == SE_BLADE) \
|| (SOURCE_ENGINE == SE_CSGO) \
|| (SOURCE_ENGINE == SE_PVKII) \
|| (SOURCE_ENGINE == SE_MCV)
return true;
#else
return false;
#endif
}
void CoreProviderImpl::LogToGame(const char *message)
{
Engine_LogPrintWrapper(message);
}
void CoreProviderImpl::ConPrint(const char *message)
{
META_CONPRINT(message);
}
void CoreProviderImpl::ConsolePrint(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
UTIL_ConsolePrintVa(fmt, ap);
va_end(ap);
}
void CoreProviderImpl::ConsolePrintVa(const char *message, va_list ap)
{
UTIL_ConsolePrintVa(message, ap);
}
bool CoreProviderImpl::IsMapLoading()
{
return g_SourceMod.IsMapLoading();
}
bool CoreProviderImpl::IsMapRunning()
{
return g_SourceMod.IsMapRunning();
}
int CoreProviderImpl::MaxClients()
{
return g_Players.MaxClients();
}
bool CoreProviderImpl::DescribePlayer(int entRef, const char **namep, const char **authp, int *useridp)
{
int index = entRef;
if (entRef & ENTREF_MASK)
{
// Unless this is an explicit entity reference, we don't know nor care if the player has an entity yet,
// as long as they are currently connected. (But if it *is* an explicit ref, validate it)
index = g_HL2.ReferenceToIndex(entRef);
}
CPlayer *player = g_Players.GetPlayerByIndex(index);
if (!player || !player->IsConnected())
return false;
if (namep)
*namep = player->GetName();
if (authp) {
const char *auth = player->GetAuthString();
*authp = (auth && *auth) ? auth : "STEAM_ID_PENDING";
}
if (useridp)
*useridp = ::engine->GetPlayerUserId(player->GetEdict());
return true;
}
int CoreProviderImpl::LoadMMSPlugin(const char *file, bool *ok, char *error, size_t maxlength)
{
bool ignore_already;
PluginId id = g_pMMPlugins->Load(file, g_PLID, ignore_already, error, maxlength);
Pl_Status status;
if (!id || (g_pMMPlugins->Query(id, NULL, &status, NULL) && status < Pl_Paused))
{
*ok = false;
}
else
{
*ok = true;
}
return id;
}
void CoreProviderImpl::UnloadMMSPlugin(int id)
{
char ignore[255];
g_pMMPlugins->Unload(id, true, ignore, sizeof(ignore));
}
bool CoreProviderImpl::IsClientConVarQueryingSupported()
{
return hooks_.GetClientCvarQueryMode() != ClientCvarQueryMode::Unavailable;
}
int CoreProviderImpl::QueryClientConVar(int client, const char *cvar)
{
#if SOURCE_ENGINE != SE_DARKMESSIAH
switch (hooks_.GetClientCvarQueryMode()) {
case ClientCvarQueryMode::DLL:
return ::engine->StartQueryCvarValue(PEntityOfEntIndex(client), cvar);
case ClientCvarQueryMode::VSP:
return serverpluginhelpers->StartQueryCvarValue(PEntityOfEntIndex(client), cvar);
default:
return InvalidQueryCvarCookie;
}
#endif
return -1;
}
void CoreProviderImpl::InitializeBridge()
{
::serverGlobals.universalTime = g_pUniversalTime;
::serverGlobals.frametime = &gpGlobals->frametime;
::serverGlobals.interval_per_tick = &gpGlobals->interval_per_tick;
this->listeners = SMGlobalClass::head;
logic_init_(this, &logicore);
// Join logic's SMGlobalClass instances.
SMGlobalClass* glob = SMGlobalClass::head;
while (glob->m_pGlobalClassNext)
glob = glob->m_pGlobalClassNext;
glob->m_pGlobalClassNext = logicore.head;
g_pThreader = logicore.threader;
translator = logicore.translator;
scripts = logicore.scripts;
sharesys = logicore.sharesys;
extsys = logicore.extsys;
g_pCoreIdent = logicore.core_ident;
handlesys = logicore.handlesys;
forwardsys = logicore.forwardsys;
adminsys = logicore.adminsys;
logger = logicore.logger;
rootmenu = logicore.rootmenu;
}
bool CoreProviderImpl::LoadBridge(char *error, size_t maxlength)
{
char file[PLATFORM_MAX_PATH];
/* Now it's time to load the logic binary */
g_SMAPI->PathFormat(file,
sizeof(file),
"%s/bin/" PLATFORM_ARCH_FOLDER "sourcemod.logic." PLATFORM_LIB_EXT,
g_SourceMod.GetSourceModPath());
char myerror[255];
logic_ = ke::SharedLib::Open(file, myerror, sizeof(myerror));
if (!logic_) {
ke::SafeSprintf(error, maxlength, "failed to load %s: %s", file, myerror);
return false;
}
LogicLoadFunction llf = logic_->get<decltype(llf)>("logic_load");
if (!llf) {
logic_ = nullptr;
ke::SafeStrcpy(error, maxlength, "could not find logic_load function");
return false;
}
GetITextParsers getitxt = logic_->get<decltype(getitxt)>("get_textparsers");
textparsers = getitxt();
logic_init_ = llf(SM_LOGIC_MAGIC);
if (!logic_init_) {
ke::SafeStrcpy(error, maxlength, "component version mismatch");
return false;
}
return true;
}
ke::RefPtr<CommandHook>
CoreProviderImpl::AddCommandHook(ConCommand *cmd, const CommandHook::Callback &callback)
{
return hooks_.AddCommandHook(cmd, callback);
}
ke::RefPtr<CommandHook>
CoreProviderImpl::AddPostCommandHook(ConCommand *cmd, const CommandHook::Callback &callback)
{
return hooks_.AddPostCommandHook(cmd, callback);
}
CoreProviderImpl::CommandImpl::CommandImpl(ConCommand *cmd, CommandHook *hook)
: cmd_(cmd),
hook_(hook)
{
}
CoreProviderImpl::CommandImpl::~CommandImpl()
{
hook_ = nullptr;
g_SMAPI->UnregisterConCommandBase(g_PLAPI, cmd_);
delete [] const_cast<char *>(cmd_->GetHelpText());
delete [] const_cast<char *>(cmd_->GetName());
delete cmd_;
}
void
CoreProviderImpl::DefineCommand(const char *name, const char *help, const CommandFunc &callback)
{
char *new_name = sm_strdup(name);
char *new_help = sm_strdup(help);
int flags = 0;
auto ignore_callback = [] (DISPATCH_ARGS) -> void {
};
ConCommand *cmd = new ConCommand(new_name, ignore_callback, new_help, flags);
ke::RefPtr<CommandHook> hook = AddCommandHook(cmd, callback);
ke::RefPtr<CommandImpl> impl = new CommandImpl(cmd, hook);
commands_.push_back(impl);
}
void CoreProviderImpl::FormatSourceBinaryName(const char *basename, char *buffer, size_t maxlength)
{
bool use_prefix = (!strcasecmp(basename, "tier0") || !strcasecmp(basename, "vstdlib"));
ke::SafeSprintf(buffer, maxlength, "%s%s%s%s", use_prefix ? SOURCE_BIN_PREFIX : "", basename, SOURCE_BIN_SUFFIX, SOURCE_BIN_EXT);
}
void CoreProviderImpl::InitializeHooks()
{
hooks_.Start();
}
void CoreProviderImpl::OnVSPReceived()
{
hooks_.OnVSPReceived();
}
void CoreProviderImpl::ShutdownHooks()
{
commands_.clear();
hooks_.Shutdown();
}
void CoreProviderImpl::ShutdownBridge()
{
logic_ = nullptr;
}
void InitLogicBridge()
{
sCoreProviderImpl.InitializeBridge();
}
bool StartLogicBridge(char *error, size_t maxlength)
{
return sCoreProviderImpl.LoadBridge(error, maxlength);
}
void ShutdownLogicBridge()
{
sCoreProviderImpl.ShutdownBridge();
}