-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoolsgoldsource.cpp
824 lines (671 loc) · 20.4 KB
/
foolsgoldsource.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
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
//========= Copyright © 2008-2023, Team Sandpit, All rights reserved. ============
//
// Purpose: Fake GoldSource engine implementation
//
// $NoKeywords: $
//================================================================================
#include "foolsgoldsource.h"
extern globalvars_t* gpGlobals;
#ifdef CLIENT_DLL
extern engine_studio_api_t IEngineStudio;
#endif // CLIENT_DLL
namespace foolsgoldsource
{
Engine gEngine;
Engine::Engine() :
engineType( EngineType::ENGINE_25ANNIVERSARY ),
bIsDedicatedServer( false ),
bIsCareerMatch( false ),
iCallsToClientCommand( 0 ),
#ifdef CLIENT_DLL
triCullStyle( TRI_FRONT ),
#endif // CLIENT_DLL
bIsFogOn( false ),
iRenderer( RENDERER_SOFTWARE )
{
memset(&this->engineFunctions, 0, sizeof(enginefuncs_t));
memset(&this->dllFunctions, 0, sizeof(DLL_FUNCTIONS));
memset(&this->newDllFunctions, 0, sizeof(NEW_DLL_FUNCTIONS));
// set up all the engine functions so they can be used
this->engineFunctions.pfnPrecacheModel = pfnPrecacheModel;
this->engineFunctions.pfnPrecacheSound = pfnPrecacheSound;
this->engineFunctions.pfnSetModel = pfnSetModel;
this->engineFunctions.pfnModelIndex = pfnModelIndex;
this->engineFunctions.pfnModelFrames = pfnModelFrames;
this->engineFunctions.pfnSetSize = pfnSetSize;
this->engineFunctions.pfnChangeLevel = pfnChangeLevel;
this->engineFunctions.pfnGetSpawnParms = pfnGetSpawnParms;
this->engineFunctions.pfnSaveSpawnParms = pfnSaveSpawnParms;
this->engineFunctions.pfnVecToYaw = pfnVecToYaw;
this->engineFunctions.pfnVecToAngles = pfnVecToAngles;
this->engineFunctions.pfnMoveToOrigin = pfnMoveToOrigin;
this->engineFunctions.pfnChangeYaw = pfnChangeYaw;
this->engineFunctions.pfnChangePitch = pfnChangePitch;
this->engineFunctions.pfnFindEntityByString = pfnFindEntityByString;
this->engineFunctions.pfnGetEntityIllum = pfnGetEntityIllum;
this->engineFunctions.pfnFindEntityInSphere = pfnFindEntityInSphere;
this->engineFunctions.pfnFindClientInPVS = pfnFindClientInPVS;
this->engineFunctions.pfnEntitiesInPVS = pfnEntitiesInPVS;
this->engineFunctions.pfnCreateEntity = pfnCreateEntity;
this->engineFunctions.pfnSetOrigin = pfnSetOrigin;
this->engineFunctions.pfnEmitSound = pfnEmitSound;
this->engineFunctions.pfnEmitAmbientSound = pfnEmitAmbientSound;
this->engineFunctions.pfnTraceSphere = pfnTraceSphere;
this->engineFunctions.pfnServerCommand = pfnServerCommand;
this->engineFunctions.pfnServerExecute = pfnServerExecute;
this->engineFunctions.pfnClientCommand = pfnClientCommand;
this->engineFunctions.pfnParticleEffect = pfnParticleEffect;
this->engineFunctions.pfnLightStyle = pfnLightStyle;
this->engineFunctions.pfnRandomLong = pfnRandomLong;
this->engineFunctions.pfnAlertMessage = pfnAlertMessage;
this->engineFunctions.pfnPvAllocEntPrivateData = pfnPvAllocEntPrivateData;
this->engineFunctions.pfnAllocString = pfnAllocString;
this->engineFunctions.pfnPEntityOfEntOffset = pfnPEntityOfEntOffset;
this->engineFunctions.pfnEntOffsetOfPEntity = pfnEntOffsetOfPEntity;
this->engineFunctions.pfnPEntityOfEntIndex = pfnPEntityOfEntIndex;
this->engineFunctions.pfnFindEntityByVars = pfnFindEntityByVars;
this->engineFunctions.pfnGetModelPtr = pfnGetModelPtr;
this->engineFunctions.pfnNameForFunction = pfnNameForFunction;
this->engineFunctions.pfnServerPrint = pfnServerPrint;
this->engineFunctions.pfnGetGameDir = pfnGetGameDir;
this->engineFunctions.pfnIsDedicatedServer = pfnIsDedicatedServer;
this->engineFunctions.pfnPrecacheEvent = pfnPrecacheEvent;
this->engineFunctions.pfnPlaybackEvent = pfnPlaybackEvent;
this->engineFunctions.pfnIsCareerMatch = pfnIsCareerMatch;
this->engineFunctions.pfnQueryClientCvarValue = pfnQueryClientCvarValue;
this->engineFunctions.pfnQueryClientCvarValue2 = pfnQueryClientCvarValue2;
this->engineFunctions.pfnCheckParm = pfnCheckParm;
this->engineFunctions.pfnPEntityOfEntIndexAllEntities = pfnPEntityOfEntIndexAllEntities;
this->dllFunctions.pfnClientCommand = ClientCommand;
this->dllFunctions.pfnServerActivate = ServerActivate;
#ifdef CLIENT_DLL
this->clientEngineFunctions.pTriAPI = &triangleApi;
this->clientEngineFunctions.pfnRegisterVariable = pfnRegisterVariable;
this->clientEngineFunctions.pfnAddCommand = pfnAddCommand;
this->clientEngineFunctions.pfnHookUserMsg = pfnHookUserMsg;
this->clientEngineFunctions.Con_DPrintf = Con_DPrintf;
this->clientEngineFunctions.pfnGetGameDirectory = pfnGetGameDirectory;
this->clientEngineFunctions.pfnGetCvarPointer = pfnGetCvarPointer;
this->clientEngineFunctions.pfnGetLevelName = pfnGetLevelName;
this->clientEngineFunctions.VGui_GetPanel = VGui_GetPanel;
this->clientEngineFunctions.pTriAPI->CullFace = CullFace;
this->clientEngineFunctions.pTriAPI->Fog = Fog;
this->clientEngineFunctions.pTriAPI->FogParams = FogParams;
this->engineStudioFunctions.GetCvar = pfnGetCvarPointer;
this->engineStudioFunctions.GetChromeSprite = GetChromeSprite;
this->engineStudioFunctions.GetModelCounters = GetModelCounters;
this->engineStudioFunctions.StudioGetBoneTransform = StudioGetBoneTransform;
this->engineStudioFunctions.StudioGetLightTransform = StudioGetLightTransform;
this->engineStudioFunctions.StudioGetAliasTransform = StudioGetAliasTransform;
this->engineStudioFunctions.StudioGetRotationMatrix = StudioGetRotationMatrix;
this->engineStudioFunctions.IsHardware = IsHardware;
#endif // CLIENT_DLL
// install the engine functions and global variables
::g_engfuncs = this->engineFunctions;
::gpGlobals = &this->globalVariables;
#ifdef CLIENT_DLL
::gEngfuncs = this->clientEngineFunctions;
::IEngineStudio = this->engineStudioFunctions;
#endif // CLIENT_DLL
// initialise the engine variables
this->globalVariables.maxClients = 32;
this->globalVariables.pStringBase = new char[Engine::iStringTableSize];
memset( const_cast<char*>(this->globalVariables.pStringBase), 0, Engine::iStringTableSize );
// start allocating at offset 1 so that checks against string_t with value 0 work
// TODO: is this how the engine works?
this->iStringTableOffset = 1;
// TODO: is edict_t* 0 is worldspawn?
for( int i = 0; i <= this->globalVariables.maxClients; i++ )
{
// TODO: player spawning should happen later - and call one of the server-side callbacks?
shared_ptr<edict_t> edict = std::make_shared<edict_t>();
edict->free = 0;
edict->v.classname = ALLOC_STRING("player");
edict->v.netname = 0;
edict->v.flags = FL_CLIENT;
this->edicts.push_back(edict);
}
this->strGameDir = "valve";
this->iMaxEdicts = 1024;
pfnRegisterVariable( const_cast<char *>("cl_himodels"), const_cast<char *>("0"), 0 );
pfnRegisterVariable( const_cast<char *>("developer"), const_cast<char *>("1"), 0 );
pfnRegisterVariable( const_cast<char *>("r_drawentities"), const_cast<char *>("1"), 0 );
}
Engine::~Engine() noexcept
{
if( this->globalVariables.pStringBase )
{
delete[] this->globalVariables.pStringBase;
this->globalVariables.pStringBase = nullptr;
}
for( size_t i = 0; i < this->clientCvars.size(); i++ )
{
shared_ptr<cvar_t> cvar = this->clientCvars[i];
delete[] cvar->name;
}
}
void Engine::Reset()
{
this->executedClientCommands.clear();
this->executedServerCommands.clear();
this->iCallsToClientCommand = 0;
}
const enginefuncs_t Engine::GetServerEngineFunctions() const
{
return this->engineFunctions;
}
const globalvars_t Engine::GetServerGlobalVariables() const
{
return this->globalVariables;
}
const DLL_FUNCTIONS *Engine::GetDLLFunctions() const
{
return &this->dllFunctions;
}
const NEW_DLL_FUNCTIONS Engine::GetNewDLLFunctions() const
{
return this->newDllFunctions;
}
#ifdef CLIENT_DLL
const cl_enginefunc_t Engine::GetClientEngineFunctions() const
{
return this->clientEngineFunctions;
}
#endif // CLIENT_DLL
const string Engine::GetGameDirectory() const
{
return this->strGameDir;
}
void Engine::SetGameDirectory( const string& strGameDir )
{
this->strGameDir = strGameDir;
}
bool Engine::GetIsDedicatedServer() const
{
return this->bIsDedicatedServer;
}
void Engine::SetIsDedicatedServer( const bool bIsDedicatedServer )
{
this->bIsDedicatedServer = bIsDedicatedServer;
}
bool Engine::GetIsCareerMatch() const
{
return this->bIsCareerMatch;
}
void Engine::SetIsCareerMatch( const bool bIsCareerMatch )
{
this->bIsCareerMatch = bIsCareerMatch;
}
#ifdef CLIENT_DLL
TRICULLSTYLE Engine::GetTriCullStyle() const
{
return this->triCullStyle;
}
void Engine::SetTriCullStyle( const TRICULLSTYLE triCullStyle )
{
this->triCullStyle = triCullStyle;
}
#endif // CLIENT_DLL
bool Engine::GetIsFogOn() const
{
return this->bIsFogOn;
}
void Engine::SetIsFogOn( const bool bIsFogOn )
{
this->bIsFogOn = bIsFogOn;
}
int Engine::GetRenderer() const
{
return this->iRenderer;
}
void Engine::SetRenderer( const int iRenderer )
{
this->iRenderer = iRenderer;
}
void Engine::SetMaxClients( const unsigned int iMaxClients )
{
this->globalVariables.maxClients = (signed int)iMaxClients;
}
const char* Engine::GetString( string_t offset )
{
return (const char*)(gpGlobals->pStringBase + (unsigned int)(offset));
}
string Util::tolowercase( const string& str )
{
string lowerCased = str;
for( unsigned int i = 0; i < str.length(); i++ )
{
// not ideal but this is how the engine would be doing it
lowerCased[i] = tolower(str[i]);
}
return lowerCased;
}
//////////////////////////////
// Fake enginefuncs_t below //
//////////////////////////////
int pfnPrecacheModel(char* s)
{
printf("Precaching %s\n", s);
// TODO: store more than just a string
gEngine.models.push_back(string(s));
return gEngine.models.size() - 1;
}
int pfnPrecacheSound(char* s)
{
printf("Precaching %s\n", s);
gEngine.sounds.push_back(string(s));
return gEngine.sounds.size() - 1;
}
void pfnSetModel(edict_t* e, const char* m)
{
// TODO: excessive calls will overflow the string table - is this what the engine does?
e->v.model = ALLOC_STRING(m);
}
int pfnModelIndex(const char* m)
{
for (unsigned int i = 0; i < gEngine.models.size(); i++)
{
if (gEngine.models[i] == Util::tolowercase(string(m)))
{
return i;
}
}
// TODO: not right - crash instead?
return -1;
}
int pfnModelFrames(int modelIndex)
{
string model = gEngine.models[modelIndex];
// TODO: return the correct value
return 0;
}
void pfnSetSize(edict_t* e, const float* rgflMin, const float* rgflMax)
{
// TODO: check this
e->v.mins.x = rgflMin[0];
e->v.mins.y = rgflMin[1];
e->v.mins.z = rgflMin[2];
e->v.maxs.x = rgflMax[0];
e->v.maxs.y = rgflMax[1];
e->v.maxs.z = rgflMax[2];
}
void pfnChangeLevel(char* s1, char* s2)
{
// TODO: set this->globalVariables.mapname
}
void pfnGetSpawnParms(edict_t* ent)
{
// TODO: does nothing?
return;
}
void pfnSaveSpawnParms(edict_t* ent)
{
// TODO: does nothing?
return;
}
float pfnVecToYaw(const float* rgflVector)
{
// TODO:
return 0.0f;
}
void pfnVecToAngles(const float* rgflVectorIn, float* rgflVectorOut)
{
// TODO:
}
void pfnMoveToOrigin( edict_t* ent, const float* pflGoal, float dist, int iMoveType )
{
ent->v.origin.x = pflGoal[0];
ent->v.origin.y = pflGoal[1];
ent->v.origin.z = pflGoal[2];
}
void pfnChangeYaw( edict_t* ent )
{
// TODO:
}
void pfnChangePitch( edict_t* ent )
{
// TODO:
}
edict_t* pfnFindEntityByString( edict_t* pEdictStartSearchAfter, const char* pszField, const char* pszValue )
{
return nullptr;
}
int pfnGetEntityIllum( edict_t* pEnt )
{
return 0;
}
edict_t* pfnFindEntityInSphere( edict_t* pEdictStartSearchAfter, const float* org, float rad )
{
return nullptr;
}
edict_t* pfnFindClientInPVS( edict_t* pEdict )
{
return nullptr;
}
edict_t* pfnEntitiesInPVS( edict_t* pplayer )
{
return nullptr;
}
edict_t* pfnCreateEntity()
{
shared_ptr<edict_t> edict = std::make_shared<edict_t>();
edict->free = 0;
gEngine.edicts.push_back(edict);
return edict.get();
}
void pfnSetOrigin( edict_t* e, const float* rgflOrigin )
{
e->v.origin[0] = rgflOrigin[0];
e->v.origin[1] = rgflOrigin[1];
e->v.origin[2] = rgflOrigin[2];
}
void pfnEmitSound( edict_t* entity, int channel, const char* sample, float volume, float attenuation, int fFlags, int pitch )
{
// TODO: check if sound exists
}
void pfnEmitAmbientSound( edict_t* entity, float* pos, const char* samp, float vol, float attenuation, int fFlags, int pitch )
{
// TODO: check if sound exists
}
void pfnTraceSphere( const float* v1, const float* v2, int fNoMonsters, float radius, edict_t* pentToSkip, TraceResult* ptr )
{
fprintf( stderr, "Not implemented\n" );
}
void pfnServerCommand( char* str )
{
gEngine.executedServerCommands.push_back( string(str) );
}
void pfnServerExecute( void )
{
// TODO: what does this do?
}
void pfnClientCommand( edict_t* pEdict, char* szFmt, ... )
{
va_list argptr;
char buffer[1024];
va_start(argptr, szFmt);
vsprintf(buffer, szFmt, argptr);
va_end(argptr);
gEngine.executedClientCommands.push_back( string(buffer) );
}
void pfnParticleEffect( const float* org, const float* dir, float color, float count )
{
// TODO: do nothing?
}
void pfnLightStyle( int style, char* val )
{
// TODO: do nothing?
}
int32 pfnRandomLong( int32 lLow, int32 lHigh )
{
return rand() % lHigh + lLow;
}
void pfnAlertMessage( ALERT_TYPE atype, char *szFmt, ... )
{
va_list argptr;
char buffer[1024];
va_start( argptr, szFmt );
vsprintf( buffer, szFmt, argptr );
va_end( argptr );
printf( "%s", buffer);
}
void* pfnPvAllocEntPrivateData( edict_t* pEdict, int32 cb )
{
pEdict->pvPrivateData = malloc( cb );
return pEdict->pvPrivateData;
}
int pfnAllocString( const char* szValue )
{
globalvars_t globalVars = gEngine.GetServerGlobalVariables();
// get the next unassigned part of the string table
const char* pCurrentOffset = globalVars.pStringBase + gEngine.iStringTableOffset;
// copy the new string to the next unassigned part of the string table
strncpy( (char*)pCurrentOffset, szValue, strlen(szValue) );
// get the newly assigned string's location
int iCurrentOffset = gEngine.iStringTableOffset;
// update the location of the next unassigned part of the string table (add 1 to terminate the string)
gEngine.iStringTableOffset += strlen(szValue) + 1;
// return the newly assigned string's location
return iCurrentOffset;
}
edict_t* pfnPEntityOfEntOffset( int iEntOffset )
{
if( (unsigned int)iEntOffset >= gEngine.edicts.size() )
{
return nullptr;
}
else
{
return gEngine.edicts[iEntOffset].get();
}
}
int pfnEntOffsetOfPEntity( const edict_t* pEdict )
{
// TODO: what is this function meant to return?
return 1;
}
edict_t* pfnPEntityOfEntIndex( int iEntIndex )
{
edict_t* result;
// TODO: is pfnPEntityOfEntOffset the same as EDICT_NUM?
if( iEntIndex < 0 ||
iEntIndex >= gEngine.iMaxEdicts ||
( (result = pfnPEntityOfEntOffset( iEntIndex )) == nullptr || result->free || !result->pvPrivateData ) &&
( iEntIndex >= gEngine.GetServerGlobalVariables().maxClients || result->free ) ) // this check on result fails if there are no edicts - never happens in GoldSource?
{
result = nullptr;
}
return result;
}
edict_t* pfnFindEntityByVars( struct entvars_s* pvars )
{
edict_t* result = nullptr;
for( size_t i = 0; i < gEngine.edicts.size(); i++ )
{
edict_t* current = gEngine.edicts[i].get();
if( ¤t->v == pvars )
{
result = current;
break;
}
}
return result;
}
void* pfnGetModelPtr( edict_t* pEdict )
{
// TODO: make it return something
return nullptr;
}
const char* pfnNameForFunction( uint32 function )
{
// TODO: implement
return nullptr;
}
void pfnServerPrint( const char* szMsg )
{
printf( "%s", szMsg );
}
void pfnGetGameDir( char *szGetGameDir )
{
strncpy( szGetGameDir, gEngine.GetGameDirectory().c_str(), gEngine.GetGameDirectory().size() );
}
int pfnIsDedicatedServer( void )
{
return gEngine.GetIsDedicatedServer();
}
unsigned short pfnPrecacheEvent( int type, const char* psz )
{
printf( "Precaching %s\n", psz );
event_t event;
// down-cast so that it's a valid index - should never have too many events anyway
event.iIndex = (unsigned short)gEngine.events.size();
event.strEventFileName = string(psz);
event.iType = type;
gEngine.events.push_back(event);
return event.iIndex;
}
void pfnPlaybackEvent( int flags, const edict_t* pInvoker, unsigned short eventindex, float delay, float* origin, float* angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2 )
{
bool bEventFound = false;
for (unsigned int i = 0; i < gEngine.events.size(); i++)
{
if (gEngine.events[i].iIndex == eventindex)
{
bEventFound = true;
}
}
if (!bEventFound)
{
// TODO: error out?
}
}
int pfnIsCareerMatch( void )
{
return gEngine.GetIsCareerMatch();
}
void pfnQueryClientCvarValue( const edict_t* player, const char* cvarName )
{
}
void pfnQueryClientCvarValue2( const edict_t* player, const char* cvarName, int requestID )
{
}
int pfnCheckParm( const char* pchCmdLineToken, char** ppnext )
{
return 0;
}
edict_t* pfnPEntityOfEntIndexAllEntities( int iEntIndex )
{
edict_t* result;
// TODO: is pfnPEntityOfEntOffset the same as EDICT_NUM?
if( iEntIndex < 0 ||
iEntIndex >= gEngine.iMaxEdicts ||
( (result = pfnPEntityOfEntOffset( iEntIndex )) == nullptr || result->free || !result->pvPrivateData ) &&
( iEntIndex > gEngine.GetServerGlobalVariables().maxClients || result->free ) ) // this check on result fails if there are no edicts - never happens in GoldSource?
{
result = nullptr;
}
return result;
}
//////////////////////////////
// Fake DLL_FUNCTIONS below //
//////////////////////////////
void ClientCommand( edict_t* pEntity )
{
gEngine.iCallsToClientCommand++;
}
void ServerActivate( edict_t* pEdictList, int edictCount, int clientMax )
{
}
////////////////////////////////
// Fake cl_enginefunc_t below //
////////////////////////////////
struct cvar_s* pfnRegisterVariable( char* szName, char* szValue, int flags )
{
shared_ptr<cvar_t> cvar = std::make_shared<cvar_t>();
cvar->name = new char[16];
strncpy( cvar->name, szName, strlen(szName) );
cvar->name[strlen(szName)] = '\0';
cvar->value = atof( szValue );
cvar->flags = flags;
gEngine.clientCvars.push_back(cvar);
return cvar.get();
}
int pfnAddCommand( char* cmd_name, void (*pfnEngSrc_function)(void) )
{
clientCommand_t clientCommand;
clientCommand.iIndex = gEngine.userMessages.size();
clientCommand.strCommandName = string(cmd_name);
#ifdef CLIENT_DLL
clientCommand.pfnFunction = pfnEngSrc_function;
#endif // CLIENT_DLL
gEngine.clientCommands.push_back(clientCommand);
return clientCommand.iIndex;
}
#ifdef CLIENT_DLL
int pfnHookUserMsg( char* szMsgName, pfnUserMsgHook pfn )
{
userMessage_t userMessage;
userMessage.iIndex = gEngine.userMessages.size();
userMessage.strMessageName = string(szMsgName);
userMessage.pfnFunction = pfn;
gEngine.userMessages.push_back(userMessage);
return userMessage.iIndex;
}
#endif // CLIENT_DLL
void Con_DPrintf( char* fmt, ... )
{
va_list argptr;
char buffer[1024];
va_start( argptr, fmt );
vsprintf( buffer, fmt, argptr );
va_end( argptr );
printf( "%s", buffer );
}
const char* pfnGetGameDirectory( void )
{
return gEngine.GetGameDirectory().c_str();
}
struct cvar_s* pfnGetCvarPointer( const char* szName )
{
for( size_t i = 0; i < gEngine.clientCvars.size(); i++ )
{
shared_ptr<cvar_t> cvar = gEngine.clientCvars[i];
if( !strcmp( cvar->name, szName ) )
{
return cvar.get();
}
}
return nullptr;
}
const char* pfnGetLevelName( void )
{
return "maps/test.bsp";
}
#ifdef CLIENT_DLL
void* VGui_GetPanel()
{
return new ::vgui::Panel();
}
void CullFace( TRICULLSTYLE style )
{
gEngine.SetTriCullStyle( style );
}
#endif // CLIENT_DLL
void Fog( float flFogColor[3], float flStart, float flEnd, int bOn )
{
gEngine.SetIsFogOn( bOn != 0 );
}
void FogParams( float flDensity, int iFogSkybox )
{
}
////////////////////////////////////
// Fake engine_studio_api_t below //
////////////////////////////////////
struct model_s* GetChromeSprite( void )
{
return nullptr;
}
void GetModelCounters( int** s, int** a )
{
}
float**** StudioGetBoneTransform( void )
{
return nullptr;
}
float**** StudioGetLightTransform( void )
{
return nullptr;
}
float*** StudioGetAliasTransform( void )
{
return nullptr;
}
float*** StudioGetRotationMatrix( void )
{
return nullptr;
}
int IsHardware( void )
{
return gEngine.GetRenderer();
}
}