-
-
Notifications
You must be signed in to change notification settings - Fork 453
/
Copy pathCClientGame.cpp
7017 lines (6055 loc) · 264 KB
/
CClientGame.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
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/CClientGame.cpp
* PURPOSE: Client game manager
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/
#include "StdInc.h"
#include <net/SyncStructures.h>
#include <game/C3DMarkers.h>
#include <game/CAnimBlendAssocGroup.h>
#include <game/CAnimBlendAssociation.h>
#include <game/CAnimBlendHierarchy.h>
#include <game/CAnimManager.h>
#include <game/CColPoint.h>
#include <game/CEventDamage.h>
#include <game/CExplosionManager.h>
#include <game/CFire.h>
#include <game/CGarage.h>
#include <game/CGarages.h>
#include <game/CPedIntelligence.h>
#include <game/CPlayerInfo.h>
#include <game/CSettings.h>
#include <game/CStreaming.h>
#include <game/CTaskManager.h>
#include <game/CWanted.h>
#include <game/CWeapon.h>
#include <game/CWeaponStatManager.h>
#include <game/CWeather.h>
#include <game/Task.h>
#include <game/CBuildingRemoval.h>
#include <windowsx.h>
#include "CServerInfo.h"
SString StringZeroPadout(const SString& strInput, uint uiPadoutSize)
{
SString strResult = strInput;
while (strResult.length() < uiPadoutSize)
strResult += '\0';
return strResult;
}
using SharedUtil::CalcMTASAPath;
using std::list;
using std::vector;
// Hide the "conversion from 'unsigned long' to 'DWORD*' of greater size" warning
#pragma warning(disable : 4312)
// Used within this file by the packet handler to grab the this pointer of CClientGame
extern CClientGame* g_pClientGame;
extern int g_iDamageEventLimit;
float g_fApplyDamageLastAmount;
uchar g_ucApplyDamageLastHitZone;
CClientPed* g_pApplyDamageLastDamagedPed;
bool g_bBulletFireVectorsValid;
CVector g_vecBulletFireStartPosition;
CVector g_vecBulletFireEndPosition;
#define DEFAULT_GRAVITY 0.008f
#define DEFAULT_GAME_SPEED 1.0f
#define DEFAULT_JETPACK_MAXHEIGHT 100
#define DEFAULT_AIRCRAFT_MAXHEIGHT 800
#define DEFAULT_AIRCRAFT_MAXVELOCITY 1.5f
#define DEFAULT_MINUTE_DURATION 1000
#define DOUBLECLICK_TIMEOUT 330
#define DOUBLECLICK_MOVE_THRESHOLD 10.0f
static constexpr long long TIME_DISCORD_UPDATE_RATE = 15000;
CClientGame::CClientGame(bool bLocalPlay) : m_ServerInfo(new CServerInfo())
{
// Init the global var with ourself
g_pClientGame = this;
// Packet handler
m_pPacketHandler = new CPacketHandler();
// Init
m_bLocalPlay = bLocalPlay;
m_bErrorStartingLocal = false;
m_iLocalConnectAttempts = 0;
m_Status = CClientGame::STATUS_CONNECTING;
m_ulVerifyTimeStart = 0;
m_ulLastClickTick = 0;
m_pLocalPlayer = NULL;
m_LocalID = INVALID_ELEMENT_ID;
m_bShowNametags = true;
m_bWaitingForLocalConnect = false;
m_bShowRadar = false;
m_bGameLoaded = false;
m_bTriggeredIngameAndConnected = false;
m_bGracefulDisconnect = false;
m_pTargetedEntity = NULL;
m_TargetedPlayerID = INVALID_ELEMENT_ID;
m_pDamageEntity = NULL;
m_DamagerID = INVALID_ELEMENT_ID;
m_ucDamageBodyPiece = 0xFF;
m_ucDamageWeapon = 0xFF;
m_ulDamageTime = 0;
m_bDamageSent = true;
m_bShowNetstat = false;
m_bShowFPS = false;
m_bHudAreaNameDisabled = false;
m_fGameSpeed = 1.0f;
m_lMoney = 0;
m_dwWanted = 0;
m_timeLastDiscordStateUpdate = 0;
m_lastWeaponSlot = WEAPONSLOT_MAX; // last stored weapon slot, for weapon slot syncing to server (sets to invalid value)
ResetAmmoInClip();
m_bFocused = g_pCore->IsFocused();
m_bCursorEventsEnabled = false;
m_bInitiallyFadedOut = true;
m_bIsPlayingBack = false;
m_bFirstPlaybackFrame = false;
// Setup game glitch defaults ( false = disabled ). Remember to update these serverside if you alter them!
m_Glitches[GLITCH_QUICKRELOAD] = false;
g_pMultiplayer->DisableQuickReload(true);
m_Glitches[GLITCH_FASTFIRE] = false;
m_Glitches[GLITCH_FASTMOVE] = false;
m_Glitches[GLITCH_CROUCHBUG] = false;
m_Glitches[GLITCH_CLOSEDAMAGE] = false;
g_pMultiplayer->DisableCloseRangeDamage(true);
m_Glitches[GLITCH_HITANIM] = false;
m_Glitches[GLITCH_FASTSPRINT] = false;
m_Glitches[GLITCH_BADDRIVEBYHITBOX] = false;
m_Glitches[GLITCH_QUICKSTAND] = false;
m_Glitches[GLITCH_KICKOUTOFVEHICLE_ONMODELREPLACE] = false;
g_pMultiplayer->DisableBadDrivebyHitboxes(true);
// Remove Night & Thermal vision view (if enabled).
g_pMultiplayer->SetNightVisionEnabled(false, true);
g_pMultiplayer->SetThermalVisionEnabled(false, true);
m_bCloudsEnabled = true;
m_bBirdsEnabled = true;
m_bWasMinimized = false;
// Grab the mod path
m_strModRoot = g_pCore->GetModInstallRoot("deathmatch");
// Figure out which directory to use for the client resource file cache
SetFileCacheRoot();
// Override CGUI's global events
g_pCore->GetGUI()->SetKeyDownHandler(INPUT_MOD, GUI_CALLBACK_KEY(&CClientGame::OnKeyDown, this));
g_pCore->GetGUI()->SetMouseClickHandler(INPUT_MOD, GUI_CALLBACK_MOUSE(&CClientGame::OnMouseClick, this));
g_pCore->GetGUI()->SetMouseDoubleClickHandler(INPUT_MOD, GUI_CALLBACK_MOUSE(&CClientGame::OnMouseDoubleClick, this));
g_pCore->GetGUI()->SetMouseButtonDownHandler(INPUT_MOD, GUI_CALLBACK_MOUSE(&CClientGame::OnMouseButtonDown, this));
g_pCore->GetGUI()->SetMouseButtonUpHandler(INPUT_MOD, GUI_CALLBACK_MOUSE(&CClientGame::OnMouseButtonUp, this));
g_pCore->GetGUI()->SetMouseMoveHandler(INPUT_MOD, GUI_CALLBACK_MOUSE(&CClientGame::OnMouseMove, this));
g_pCore->GetGUI()->SetMouseEnterHandler(INPUT_MOD, GUI_CALLBACK_MOUSE(&CClientGame::OnMouseEnter, this));
g_pCore->GetGUI()->SetMouseLeaveHandler(INPUT_MOD, GUI_CALLBACK_MOUSE(&CClientGame::OnMouseLeave, this));
g_pCore->GetGUI()->SetMouseWheelHandler(INPUT_MOD, GUI_CALLBACK_MOUSE(&CClientGame::OnMouseWheel, this));
g_pCore->GetGUI()->SetMovedHandler(INPUT_MOD, GUI_CALLBACK(&CClientGame::OnMove, this));
g_pCore->GetGUI()->SetSizedHandler(INPUT_MOD, GUI_CALLBACK(&CClientGame::OnSize, this));
g_pCore->GetGUI()->SetFocusGainedHandler(INPUT_MOD, GUI_CALLBACK_FOCUS(&CClientGame::OnFocusGain, this));
g_pCore->GetGUI()->SetFocusLostHandler(INPUT_MOD, GUI_CALLBACK_FOCUS(&CClientGame::OnFocusLoss, this));
g_pCore->GetGUI()->SelectInputHandlers(INPUT_MOD);
// Startup "entities from root" optimization for getElementsByType
CClientEntity::StartupEntitiesFromRoot();
// Startup game entity tracking manager
m_pModelCacheManager = NewClientModelCacheManager();
// Initialize our root entity with an invalid id, we dont know the true id until map-start
m_pRootEntity = new CClientDummy(NULL, INVALID_ELEMENT_ID, "root");
m_pRootEntity->MakeSystemEntity();
m_pDebugHookManager = new CDebugHookManager();
// Movings objects manager
m_pMovingObjectsManager = new CMovingObjectsManager();
// Create the manager and grab the most important pointers
m_pManager = new CClientManager;
m_pCamera = m_pManager->GetCamera();
m_pMarkerManager = m_pManager->GetMarkerManager();
m_pObjectManager = m_pManager->GetObjectManager();
m_pPickupManager = m_pManager->GetPickupManager();
m_pPlayerManager = m_pManager->GetPlayerManager();
m_pRadarAreaManager = m_pManager->GetRadarAreaManager();
m_pDisplayManager = m_pManager->GetDisplayManager();
m_pVehicleManager = m_pManager->GetVehicleManager();
m_pRadarMarkerManager = m_pManager->GetRadarMarkerManager();
m_pPathManager = m_pManager->GetPathManager();
m_pTeamManager = m_pManager->GetTeamManager();
m_pPedManager = m_pManager->GetPedManager();
m_pGUIManager = m_pManager->GetGUIManager();
m_pResourceManager = m_pManager->GetResourceManager();
m_pProjectileManager = m_pManager->GetProjectileManager();
m_pLocalServer = NULL;
m_pLatentTransferManager = new CLatentTransferManager();
m_pZoneNames = new CZoneNames;
m_pScriptKeyBinds = new CScriptKeyBinds;
m_pRemoteCalls = new CRemoteCalls();
m_pResourceFileDownloadManager = new CResourceFileDownloadManager();
// Create our net API
m_pNetAPI = new CNetAPI(m_pManager);
m_pNetworkStats = new CNetworkStats(m_pDisplayManager);
m_pSyncDebug = new CSyncDebug(m_pManager);
// Create our blended weather class
m_pBlendedWeather = new CBlendedWeather;
// Create our RPC class
m_pRPCFunctions = new CRPCFunctions(this);
// Our management classes
m_pUnoccupiedVehicleSync = new CUnoccupiedVehicleSync(m_pVehicleManager);
m_pPedSync = new CPedSync(m_pPedManager);
#ifdef WITH_OBJECT_SYNC
m_pObjectSync = new CObjectSync(m_pObjectManager);
#endif
m_pNametags = new CNametags(m_pManager);
m_pRadarMap = new CRadarMap(m_pManager);
// Set the screenshot path
/* This is now done in CCore, to maintain a global screenshot path
SString strScreenShotPath = SString::Printf ( "%s\\screenshots", m_szModRoot );
g_pCore->SetScreenShotPath ( strScreenShotPath );
*/
// Create the transfer boxes (GUI)
m_pTransferBox = new CTransferBox(TransferBoxType::RESOURCE_DOWNLOAD);
m_pBigPacketTransferBox = new CTransferBox(TransferBoxType::MAP_DOWNLOAD);
// Store the time we started on
if (bLocalPlay)
m_ulTimeStart = 0;
else
m_ulTimeStart = CClientTime::GetTime();
// MTA Voice
m_pVoiceRecorder = new CVoiceRecorder();
// Singular file download manager
m_pSingularFileDownloadManager = new CSingularFileDownloadManager();
// Register the message and the net packet handler
g_pMultiplayer->SetPreWeaponFireHandler(CClientGame::PreWeaponFire);
g_pMultiplayer->SetPostWeaponFireHandler(CClientGame::PostWeaponFire);
g_pMultiplayer->SetBulletImpactHandler(CClientGame::BulletImpact);
g_pMultiplayer->SetBulletFireHandler(CClientGame::BulletFire);
g_pMultiplayer->SetExplosionHandler(CClientExplosionManager::Hook_StaticExplosionCreation);
g_pMultiplayer->SetBreakTowLinkHandler(CClientGame::StaticBreakTowLinkHandler);
g_pMultiplayer->SetDrawRadarAreasHandler(CClientGame::StaticDrawRadarAreasHandler);
g_pMultiplayer->SetDamageHandler(CClientGame::StaticDamageHandler);
g_pMultiplayer->SetDeathHandler(CClientGame::StaticDeathHandler);
g_pMultiplayer->SetFireHandler(CClientGame::StaticFireHandler);
g_pMultiplayer->SetProjectileStopHandler(CClientProjectileManager::Hook_StaticProjectileAllow);
g_pMultiplayer->SetProjectileHandler(CClientProjectileManager::Hook_StaticProjectileCreation);
g_pMultiplayer->SetRender3DStuffHandler(CClientGame::StaticRender3DStuffHandler);
g_pMultiplayer->SetPreRenderSkyHandler(CClientGame::StaticPreRenderSkyHandler);
g_pMultiplayer->SetRenderHeliLightHandler(CClientGame::StaticRenderHeliLightHandler);
g_pMultiplayer->SetChokingHandler(CClientGame::StaticChokingHandler);
g_pMultiplayer->SetPreWorldProcessHandler(CClientGame::StaticPreWorldProcessHandler);
g_pMultiplayer->SetPostWorldProcessHandler(CClientGame::StaticPostWorldProcessHandler);
g_pMultiplayer->SetPostWorldProcessPedsAfterPreRenderHandler(CClientGame::StaticPostWorldProcessPedsAfterPreRenderHandler);
g_pMultiplayer->SetPreFxRenderHandler(CClientGame::StaticPreFxRenderHandler);
g_pMultiplayer->SetPostColorFilterRenderHandler(CClientGame::StaticPostColorFilterRenderHandler);
g_pMultiplayer->SetPreHudRenderHandler(CClientGame::StaticPreHudRenderHandler);
g_pMultiplayer->DisableCallsToCAnimBlendNode(false);
g_pMultiplayer->SetCAnimBlendAssocDestructorHandler(CClientGame::StaticCAnimBlendAssocDestructorHandler);
g_pMultiplayer->SetAddAnimationHandler(CClientGame::StaticAddAnimationHandler);
g_pMultiplayer->SetAddAnimationAndSyncHandler(CClientGame::StaticAddAnimationAndSyncHandler);
g_pMultiplayer->SetAssocGroupCopyAnimationHandler(CClientGame::StaticAssocGroupCopyAnimationHandler);
g_pMultiplayer->SetBlendAnimationHierarchyHandler(CClientGame::StaticBlendAnimationHierarchyHandler);
g_pMultiplayer->SetProcessCollisionHandler(CClientGame::StaticProcessCollisionHandler);
g_pMultiplayer->SetVehicleCollisionHandler(CClientGame::StaticVehicleCollisionHandler);
g_pMultiplayer->SetVehicleDamageHandler(CClientGame::StaticVehicleDamageHandler);
g_pMultiplayer->SetHeliKillHandler(CClientGame::StaticHeliKillHandler);
g_pMultiplayer->SetObjectDamageHandler(CClientGame::StaticObjectDamageHandler);
g_pMultiplayer->SetObjectBreakHandler(CClientGame::StaticObjectBreakHandler);
g_pMultiplayer->SetWaterCannonHitHandler(CClientGame::StaticWaterCannonHandler);
g_pMultiplayer->SetVehicleFellThroughMapHandler(CClientGame::StaticVehicleFellThroughMapHandler);
g_pMultiplayer->SetGameObjectDestructHandler(CClientGame::StaticGameObjectDestructHandler);
g_pMultiplayer->SetGameVehicleDestructHandler(CClientGame::StaticGameVehicleDestructHandler);
g_pMultiplayer->SetGamePlayerDestructHandler(CClientGame::StaticGamePlayerDestructHandler);
g_pMultiplayer->SetGameProjectileDestructHandler(CClientGame::StaticGameProjectileDestructHandler);
g_pMultiplayer->SetGameModelRemoveHandler(CClientGame::StaticGameModelRemoveHandler);
g_pMultiplayer->SetGameRunNamedAnimDestructorHandler(CClientGame::StaticGameRunNamedAnimDestructorHandler);
g_pMultiplayer->SetGameEntityRenderHandler(CClientGame::StaticGameEntityRenderHandler);
g_pMultiplayer->SetFxSystemDestructionHandler(CClientGame::StaticFxSystemDestructionHandler);
g_pMultiplayer->SetDrivebyAnimationHandler(CClientGame::StaticDrivebyAnimationHandler);
g_pMultiplayer->SetPedStepHandler(CClientGame::StaticPedStepHandler);
g_pMultiplayer->SetVehicleWeaponHitHandler(CClientGame::StaticVehicleWeaponHitHandler);
g_pMultiplayer->SetAudioZoneRadioSwitchHandler(CClientGame::StaticAudioZoneRadioSwitchHandler);
g_pGame->SetPreWeaponFireHandler(CClientGame::PreWeaponFire);
g_pGame->SetPostWeaponFireHandler(CClientGame::PostWeaponFire);
g_pGame->SetTaskSimpleBeHitHandler(CClientGame::StaticTaskSimpleBeHitHandler);
g_pGame->GetAudioEngine()->SetWorldSoundHandler(CClientGame::StaticWorldSoundHandler);
g_pCore->SetMessageProcessor(CClientGame::StaticProcessMessage);
g_pCore->GetKeyBinds()->SetKeyStrokeHandler(CClientGame::StaticKeyStrokeHandler);
g_pCore->GetKeyBinds()->SetCharacterKeyHandler(CClientGame::StaticCharacterKeyHandler);
g_pNet->RegisterPacketHandler(CClientGame::StaticProcessPacket);
m_pLuaManager = new CLuaManager(this);
m_pScriptDebugging = new CScriptDebugging(m_pLuaManager);
m_pScriptDebugging->SetLogfile(CalcMTASAPath("mta\\logs\\clientscript.log"), 3);
CStaticFunctionDefinitions(m_pLuaManager, &m_Events, g_pCore, g_pGame, this, m_pManager);
CLuaFunctionDefs::Initialize(m_pLuaManager, m_pScriptDebugging, this);
CLuaDefs::Initialize(this, m_pLuaManager, m_pScriptDebugging);
// Start async task scheduler
m_pAsyncTaskScheduler = new SharedUtil::CAsyncTaskScheduler(2);
// Disable the enter/exit vehicle key button (we want to handle this button ourselves)
g_pMultiplayer->DisableEnterExitVehicleKey(true);
// Disable GTA's pickup processing as we want to confirm the hits with the server
m_pPickupManager->SetPickupProcessingDisabled(true);
// Key-bind for fire-key (for handling satchels and stealth-kills)
g_pCore->GetKeyBinds()->AddControlFunction("fire", CClientGame::StaticUpdateFireKey, true);
// Init big packet progress vars
m_bReceivingBigPacket = false;
m_ulBigPacketSize = 0;
m_ulBigPacketBytesReceivedBase = 0;
m_bBeingDeleted = false;
#if defined(MTA_DEBUG) || defined(MTA_BETA)
m_bShowSyncingInfo = false;
#endif
#ifdef MTA_DEBUG
m_pShowPlayer = m_pShowPlayerTasks = NULL;
m_bMimicLag = false;
m_ulLastMimicLag = 0;
m_bDoPaintballs = false;
m_bShowInterpolation = false;
#endif
// Add our lua events
AddBuiltInEvents();
// Load some stuff from the core config
float fScale;
g_pCore->GetCVars()->Get("text_scale", fScale);
CClientTextDisplay::SetGlobalScale(fScale);
// Reset async loading script settings to default
g_pGame->SetAsyncLoadingFromScript(true, false);
// Reset test mode script settings to default
g_pCore->GetGraphics()->GetRenderItemManager()->SetTestMode(DX_TEST_MODE_NONE);
// Setup builtin Lua events
SetupGlobalLuaEvents();
// Setup default states for Rich Presence
g_vehicleTypePrefixes = {
_("Flying a UFO around"), _("Cruising around"), _("Riding the waves of"),
_("Riding the train in"), _("Flying around"), _("Flying around"),
_("Riding around"), _("Monster truckin' around"), _("Quaddin' around"),
_("Bunny hopping around"), _("Doing weird stuff in")
};
g_playerTaskStates = {
{TASK_COMPLEX_JUMP, {true, _("Climbing around in"), TASK_SIMPLE_CLIMB}},
{TASK_SIMPLE_GANG_DRIVEBY, {true, _("Doing a drive-by in")}},
{TASK_SIMPLE_DRIVEBY_SHOOT, {true, _("Doing a drive-by in")}},
{TASK_SIMPLE_DIE, {false, _("Blub blub..."), TASK_SIMPLE_DROWN}},
{TASK_SIMPLE_DIE, {false, _("Breathing water"), TASK_SIMPLE_DROWN}},
{TASK_SIMPLE_DIE, {true, _("Drowning in"), TASK_SIMPLE_DROWN}},
{TASK_SIMPLE_PLAYER_ON_FOOT, {true, _("Ducking for cover in"), {}, TASK_SIMPLE_DUCK, TASK_SECONDARY_DUCK}},
{TASK_SIMPLE_PLAYER_ON_FOOT, {true, _("Fighting in"), {}, TASK_SIMPLE_FIGHT, TASK_SECONDARY_ATTACK}},
{TASK_SIMPLE_PLAYER_ON_FOOT, {true, _("Throwing fists in"), {}, TASK_SIMPLE_FIGHT, TASK_SECONDARY_ATTACK}},
{TASK_SIMPLE_PLAYER_ON_FOOT, {true, _("Blastin' fools in"), {}, TASK_SIMPLE_USE_GUN, TASK_SECONDARY_ATTACK}},
{TASK_SIMPLE_PLAYER_ON_FOOT, {true, _("Shooting up"), {}, TASK_SIMPLE_USE_GUN, TASK_SECONDARY_ATTACK}},
{TASK_SIMPLE_JETPACK, {true, _("Jetpacking in")}},
{TASK_SIMPLE_PLAYER_ON_FOOT, {true, _("Literally on fire in"), {}, TASK_SIMPLE_PLAYER_ON_FIRE, TASK_SECONDARY_PARTIAL_ANIM}},
{TASK_SIMPLE_PLAYER_ON_FOOT, {true, _("Burning up in"), {}, TASK_SIMPLE_PLAYER_ON_FIRE, TASK_SECONDARY_PARTIAL_ANIM}},
{TASK_COMPLEX_IN_WATER, {true, _("Swimming in"), TASK_SIMPLE_SWIM}},
{TASK_COMPLEX_IN_WATER, {true, _("Floating around in"), TASK_SIMPLE_SWIM}},
{TASK_COMPLEX_IN_WATER, {false, _("Being chased by a shark"), TASK_SIMPLE_SWIM}},
{TASK_SIMPLE_CHOKING, {true, _("Choking to death in")}},
};
}
CClientGame::~CClientGame()
{
m_bBeingDeleted = true;
// Stop all explosions. Unfortunately this doesn't fix the crash
// if a vehicle is destroyed while it explodes.
g_pGame->GetExplosionManager()->RemoveAllExplosions();
// Reset custom streaming memory size [possibly] set by the server...
g_pCore->SetCustomStreamingMemory(0);
// ...and restore the buffer size too
g_pGame->GetStreaming()->SetStreamingBufferSize(g_pClientGame->GetManager()->GetIMGManager()->GetLargestFileSizeBlocks());
// Reset camera shaking
g_pGame->GetCamera()->SetShakeForce(0.0f);
// Stop playing the continuous sounds
// if the game was loaded. This is done by
// playing these special IDS.
if (m_bGameLoaded)
{
g_pGame->GetAudioEngine()->PlayFrontEndSound(35);
g_pGame->GetAudioEngine()->PlayFrontEndSound(48);
}
// Reset the GUI input mode
g_pCore->GetGUI()->SetGUIInputMode(INPUTMODE_NO_BINDS_ON_EDIT);
// Reset CGUI's global events
g_pCore->GetGUI()->ClearInputHandlers(INPUT_MOD);
// Destroy mimics
#ifdef MTA_DEBUG
list<CClientPlayer*>::const_iterator iterMimics = m_Mimics.begin();
for (; iterMimics != m_Mimics.end(); iterMimics++)
{
CClientPlayer* pPlayer = *iterMimics;
CClientVehicle* pVehicle = pPlayer->GetOccupiedVehicle();
if (pVehicle)
delete pVehicle;
delete pPlayer;
}
#endif
// Hide the transfer box incase it is showing
m_pTransferBox->Hide();
m_pBigPacketTransferBox->Hide();
// Stop async task scheduler
SAFE_DELETE(m_pAsyncTaskScheduler);
SAFE_DELETE(m_pVoiceRecorder);
// Singular file download manager
SAFE_DELETE(m_pSingularFileDownloadManager);
// NULL the message/net stuff
g_pMultiplayer->SetPreContextSwitchHandler(NULL);
g_pMultiplayer->SetPostContextSwitchHandler(NULL);
g_pMultiplayer->SetPreWeaponFireHandler(NULL);
g_pMultiplayer->SetPostWeaponFireHandler(NULL);
g_pMultiplayer->SetBulletImpactHandler(NULL);
g_pMultiplayer->SetBulletFireHandler(NULL);
g_pMultiplayer->SetExplosionHandler(NULL);
g_pMultiplayer->SetBreakTowLinkHandler(NULL);
g_pMultiplayer->SetDrawRadarAreasHandler(NULL);
g_pMultiplayer->SetDamageHandler(NULL);
g_pMultiplayer->SetFireHandler(NULL);
g_pMultiplayer->SetProjectileStopHandler(NULL);
g_pMultiplayer->SetProjectileHandler(NULL);
g_pMultiplayer->SetProcessCamHandler(nullptr);
g_pMultiplayer->SetRender3DStuffHandler(NULL);
g_pMultiplayer->SetPreRenderSkyHandler(NULL);
g_pMultiplayer->SetRenderHeliLightHandler(nullptr);
g_pMultiplayer->SetChokingHandler(NULL);
g_pMultiplayer->SetPreWorldProcessHandler(NULL);
g_pMultiplayer->SetPostWorldProcessHandler(NULL);
g_pMultiplayer->SetPostWorldProcessPedsAfterPreRenderHandler(nullptr);
g_pMultiplayer->SetPreFxRenderHandler(NULL);
g_pMultiplayer->SetPostColorFilterRenderHandler(nullptr);
g_pMultiplayer->SetPreHudRenderHandler(NULL);
g_pMultiplayer->DisableCallsToCAnimBlendNode(true);
g_pMultiplayer->SetCAnimBlendAssocDestructorHandler(NULL);
g_pMultiplayer->SetAddAnimationHandler(NULL);
g_pMultiplayer->SetAddAnimationAndSyncHandler(NULL);
g_pMultiplayer->SetAssocGroupCopyAnimationHandler(NULL);
g_pMultiplayer->SetBlendAnimationHierarchyHandler(NULL);
g_pMultiplayer->SetProcessCollisionHandler(NULL);
g_pMultiplayer->SetVehicleCollisionHandler(NULL);
g_pMultiplayer->SetVehicleDamageHandler(NULL);
g_pMultiplayer->SetHeliKillHandler(NULL);
g_pMultiplayer->SetObjectDamageHandler(NULL);
g_pMultiplayer->SetObjectBreakHandler(NULL);
g_pMultiplayer->SetWaterCannonHitHandler(NULL);
g_pMultiplayer->SetGameObjectDestructHandler(NULL);
g_pMultiplayer->SetGameVehicleDestructHandler(NULL);
g_pMultiplayer->SetGamePlayerDestructHandler(NULL);
g_pMultiplayer->SetGameProjectileDestructHandler(NULL);
g_pMultiplayer->SetGameModelRemoveHandler(NULL);
g_pMultiplayer->SetGameRunNamedAnimDestructorHandler(nullptr);
g_pMultiplayer->SetGameEntityRenderHandler(NULL);
g_pMultiplayer->SetDrivebyAnimationHandler(nullptr);
g_pMultiplayer->SetPedStepHandler(nullptr);
g_pMultiplayer->SetVehicleWeaponHitHandler(nullptr);
g_pMultiplayer->SetAudioZoneRadioSwitchHandler(nullptr);
g_pGame->SetPreWeaponFireHandler(NULL);
g_pGame->SetPostWeaponFireHandler(NULL);
g_pGame->SetTaskSimpleBeHitHandler(NULL);
g_pGame->GetAudioEngine()->SetWorldSoundHandler(NULL);
g_pCore->SetMessageProcessor(NULL);
g_pCore->GetKeyBinds()->SetKeyStrokeHandler(NULL);
g_pCore->GetKeyBinds()->SetCharacterKeyHandler(NULL);
g_pNet->StopNetwork();
g_pNet->RegisterPacketHandler(NULL);
CKeyBindsInterface* pKeyBinds = g_pCore->GetKeyBinds();
pKeyBinds->RemoveAllFunctions(CClientGame::StaticProcessClientKeyBind);
pKeyBinds->RemoveAllControlFunctions(CClientGame::StaticProcessClientControlBind);
pKeyBinds->RemoveAllFunctions(CClientGame::StaticProcessServerKeyBind);
pKeyBinds->RemoveAllControlFunctions(CClientGame::StaticProcessServerControlBind);
pKeyBinds->RemoveAllControlFunctions(CClientGame::StaticUpdateFireKey);
pKeyBinds->SetAllControlsEnabled(true, true, true);
g_pCore->ForceCursorVisible(false);
SetCursorEventsEnabled(false);
// Reset discord stuff
const auto discord = g_pCore->GetDiscord();
if (discord && discord->IsDiscordRPCEnabled())
{
discord->ResetDiscordData();
discord->SetPresenceState(_("Main menu"), false);
discord->UpdatePresence();
}
// Destroy our stuff
SAFE_DELETE(m_pManager); // Will trigger onClientResourceStop
SAFE_DELETE(m_pNametags);
SAFE_DELETE(m_pSyncDebug);
SAFE_DELETE(m_pNetworkStats);
SAFE_DELETE(m_pNetAPI);
SAFE_DELETE(m_pRPCFunctions);
SAFE_DELETE(m_pUnoccupiedVehicleSync);
SAFE_DELETE(m_pPedSync);
#ifdef WITH_OBJECT_SYNC
SAFE_DELETE(m_pObjectSync);
#endif
SAFE_DELETE(m_pBlendedWeather);
SAFE_DELETE(m_pMovingObjectsManager);
SAFE_DELETE(m_pRadarMap);
SAFE_DELETE(m_pRemoteCalls);
SAFE_DELETE(m_pLuaManager);
SAFE_DELETE(m_pLatentTransferManager);
SAFE_DELETE(m_pResourceFileDownloadManager);
SAFE_DELETE(m_pRootEntity);
SAFE_DELETE(m_pModelCacheManager);
// SAFE_DELETE(m_pGameEntityXRefManager);
SAFE_DELETE(m_pZoneNames);
SAFE_DELETE(m_pScriptKeyBinds);
// Delete the scriptdebugger
SAFE_DELETE(m_pScriptDebugging);
// Delete the transfer boxes
SAFE_DELETE(m_pTransferBox);
SAFE_DELETE(m_pBigPacketTransferBox);
SAFE_DELETE(m_pLocalServer);
SAFE_DELETE(m_pDebugHookManager);
// Packet handler
SAFE_DELETE(m_pPacketHandler);
// Delete PerfStatManager
delete CClientPerfStatManager::GetSingleton();
// NULL the global CClientGame var
g_pClientGame = NULL;
m_bBeingDeleted = false;
CStaticFunctionDefinitions::ResetAllSurfaceInfo();
}
/*
bool CClientGame::StartGame ( void ) // for an offline game (e.g. editor)
{
m_Status = STATUS_OFFLINE;
g_pCore->SetOfflineMod ( true ); // hide chatbox etc
g_pCore->SetConnected ( true ); // not sure, but its required :)
g_pCore->HideMainMenu (); // duh
// If the game isn't started, start it
if ( g_pGame->GetSystemState () == 7 )
{
g_pGame->StartGame ();
}
return true;
}
*/
#include <crtdbg.h>
// #define _CRTDBG_CHECK_EVERY_16_DF 0x00100000 /* check heap every 16 heap ops */
// #define _CRTDBG_CHECK_EVERY_128_DF 0x00800000 /* check heap every 128 heap ops */
// #define _CRTDBG_CHECK_EVERY_1024_DF 0x04000000 /* check heap every 1024 heap ops */
void CClientGame::EnablePacketRecorder(const char* szFilename)
{
m_pManager->GetPacketRecorder()->StartRecord(szFilename, true);
}
void CClientGame::StartPlayback()
{
// strcpy ( m_szNick, "Playback" );
m_bIsPlayingBack = true;
m_bFirstPlaybackFrame = true;
m_pManager->GetPacketRecorder()->SetPacketHandler(CClientGame::StaticProcessPacket);
if (!m_pManager->IsGameLoaded())
{
g_pGame->StartGame();
}
}
bool CClientGame::StartGame(const char* szNick, const char* szPassword, eServerType Type)
{
m_ServerType = Type;
// int dbg = _CrtSetDbgFlag ( _CRTDBG_REPORT_FLAG );
// dbg |= _CRTDBG_ALLOC_MEM_DF;
// dbg |= _CRTDBG_CHECK_ALWAYS_DF;
// dbg |= _CRTDBG_DELAY_FREE_MEM_DF;
// dbg |= _CRTDBG_LEAK_CHECK_DF;
//_CrtSetDbgFlag(dbg);
// Verify that the nickname is valid
if (!IsNickValid(szNick))
{
g_pCore->ShowMessageBox(_("Error") + _E("CD01"), _("Invalid nickname! Please go to Settings and set a new one!"), MB_BUTTON_OK | MB_ICON_ERROR);
g_pCore->GetModManager()->RequestUnload();
return false;
}
// Store our nickname
m_strLocalNick.AssignLeft(szNick, MAX_PLAYER_NICK_LENGTH);
// Are we connected?
if (g_pNet->IsConnected() || m_bIsPlayingBack)
{
// Hide the console when connecting..
if (g_pCore->GetConsole()->IsVisible())
g_pCore->GetConsole()->SetVisible(false);
// Display the status box
g_pCore->ShowMessageBox(_("CONNECTING"), _("Entering the game ..."), MB_ICON_INFO);
// Send the initial data to the server
NetBitStreamInterface* pBitStream = g_pNet->AllocateNetBitStream();
if (pBitStream)
{
// Hash the password if neccessary
MD5 Password;
memset(Password.data, 0, sizeof(MD5));
if (szPassword)
{
// Is it long enough?
size_t sizePassword = strlen(szPassword);
if (sizePassword > 0)
{
// Hash the password and put it in the struct
CMD5Hasher Hasher;
Hasher.Calculate(szPassword, sizePassword, Password);
}
}
// Append version information
pBitStream->Write(static_cast<unsigned short>(MTA_DM_NETCODE_VERSION));
pBitStream->Write(static_cast<unsigned short>(MTA_DM_VERSION));
pBitStream->Write(static_cast<unsigned short>(MTA_DM_BITSTREAM_VERSION));
SString strPlayerVersion("%d.%d.%d-%d.%05d.%d", MTASA_VERSION_MAJOR, MTASA_VERSION_MINOR, MTASA_VERSION_MAINTENANCE, MTASA_VERSION_TYPE,
MTASA_VERSION_BUILD, g_pNet->GetNetRev());
pBitStream->WriteString(strPlayerVersion);
pBitStream->WriteBit(g_pCore->IsOptionalUpdateInfoRequired(g_pNet->GetConnectedServer(true)));
pBitStream->Write(static_cast<unsigned char>(g_pGame->GetGameVersion()));
// Append user details
SString strTemp = StringZeroPadout(m_strLocalNick, MAX_PLAYER_NICK_LENGTH);
pBitStream->Write(strTemp.c_str(), MAX_PLAYER_NICK_LENGTH);
pBitStream->Write(reinterpret_cast<const char*>(Password.data), sizeof(MD5));
// Append community information (Removed)
std::string strUser;
pBitStream->Write(strUser.c_str(), MAX_SERIAL_LENGTH);
// Send an empty string if server still has old Discord implementation (#2499)
if (g_pNet->CanServerBitStream(eBitStreamVersion::Discord_InitialImplementation) && !g_pNet->CanServerBitStream(eBitStreamVersion::Discord_Cleanup))
{
pBitStream->WriteString<uchar>("");
}
// Send the packet as joindata
g_pNet->SendPacket(PACKET_ID_PLAYER_JOINDATA, pBitStream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
g_pNet->DeallocateNetBitStream(pBitStream);
return true;
}
}
else
{
g_pCore->ShowMessageBox(_("Error") + _E("CD02"), _("Not connected; please use Quick Connect or the 'connect' command to connect to a server."),
MB_BUTTON_OK | MB_ICON_ERROR);
g_pCore->GetModManager()->RequestUnload();
}
return false;
}
void CClientGame::SetupLocalGame(eServerType Type)
{
SString strConfig = (Type == SERVER_TYPE_EDITOR) ? "editor.conf" : "local.conf";
m_bWaitingForLocalConnect = true;
if (!m_pLocalServer)
m_pLocalServer = new CLocalServer(strConfig);
}
bool CClientGame::StartLocalGame(eServerType Type, const char* szPassword)
{
// Verify that the nickname is valid
std::string strNick;
g_pCore->GetCVars()->Get("nick", strNick);
if (!IsNickValid(strNick.c_str()))
{
g_pCore->ShowMessageBox(_("Error") + _E("CD03"), _("Invalid nickname! Please go to Settings and set a new one!"), MB_BUTTON_OK | MB_ICON_ERROR);
g_pCore->GetModManager()->RequestUnload();
return false;
}
m_bWaitingForLocalConnect = false;
m_ServerType = Type;
SString strTemp = (Type == SERVER_TYPE_EDITOR) ? "editor.conf" : "local.conf";
SAFE_DELETE(m_pLocalServer);
// Store our nickname
m_strLocalNick.AssignLeft(strNick.c_str(), MAX_PLAYER_NICK_LENGTH);
// Got a server?
if (m_bLocalPlay)
{
// Start the server locally
if (!m_Server.Start(strTemp))
{
m_bWaitingForLocalConnect = true;
m_bErrorStartingLocal = true;
g_pCore->ShowMessageBox(_("Error") + _E("CD60"), _("Could not start the local server. See console for details."), MB_BUTTON_OK | MB_ICON_ERROR);
g_pCore->GetModManager()->RequestUnload();
return false;
}
if (szPassword)
m_Server.SetPassword(szPassword);
// Display the status box<<<<<
m_OnCancelLocalGameClick = GUI_CALLBACK(&CClientGame::OnCancelLocalGameClick, this);
g_pCore->ShowMessageBox(_("Local Server"), _("Starting local server ..."), MB_BUTTON_CANCEL | MB_ICON_INFO, &m_OnCancelLocalGameClick);
}
else
{
g_pCore->GetModManager()->RequestUnload();
return false;
}
// We're waiting for connection
m_bWaitingForLocalConnect = true;
return true;
}
bool CClientGame::OnCancelLocalGameClick(CGUIElement* pElement)
{
if (m_bLocalPlay && m_bWaitingForLocalConnect)
{
g_pCore->RemoveMessageBox();
g_pCore->GetModManager()->RequestUnload();
return true;
}
return false;
}
void CClientGame::DoPulsePreFrame()
{
if (m_Status == CClientGame::STATUS_JOINED)
{
if (m_pVoiceRecorder && m_pVoiceRecorder->IsEnabled())
{
m_pVoiceRecorder->DoPulse();
}
}
}
void CClientGame::DoPulsePreHUDRender(bool bDidUnminimize, bool bDidRecreateRenderTargets)
{
// Allow scripted dxSetRenderTarget for old scripts
g_pCore->GetGraphics()->GetRenderItemManager()->EnableSetRenderTargetOldVer(true);
// If appropriate, call onClientRestore
if (bDidUnminimize)
{
CLuaArguments Arguments;
Arguments.PushBoolean(bDidRecreateRenderTargets);
m_pRootEntity->CallEvent("onClientRestore", Arguments, false);
m_bWasMinimized = false;
// Reverse any mute on minimize effects
g_pGame->GetAudioEngine()->SetEffectsMasterVolume(g_pGame->GetSettings()->GetSFXVolume());
g_pGame->GetAudioEngine()->SetMusicMasterVolume(g_pGame->GetSettings()->GetRadioVolume());
m_pManager->GetSoundManager()->SetMinimizeMuted(false);
}
// Call onClientHUDRender LUA event
CLuaArguments Arguments;
m_pRootEntity->CallEvent("onClientHUDRender", Arguments, false);
// Disallow scripted dxSetRenderTarget for old scripts
g_pCore->GetGraphics()->GetRenderItemManager()->EnableSetRenderTargetOldVer(false);
// Restore in case script forgets
g_pCore->GetGraphics()->GetRenderItemManager()->RestoreDefaultRenderTarget();
DebugElementRender();
}
void CClientGame::DoPulsePostFrame()
{
TIMING_CHECKPOINT("+CClientGame::DoPulsePostFrame");
#ifdef DEBUG_KEYSTATES
// Get the controller state
CControllerState cs;
g_pGame->GetPad()->GetCurrentControllerState(&cs);
SString strBuffer;
strBuffer = SString::Printf(
"LeftShoulder1: %u\n"
"LeftShoulder2: %u\n"
"RightShoulder1: %u\n"
"RightShoulder2: %u\n"
"DPadUp: %u\n"
"DPadDown: %u\n"
"DPadLeft: %u\n"
"DPadRight: %u\n"
"Start: %u\n"
"Select: %u\n"
"ButtonSquare: %u\n"
"ButtonTriangle: %u\n"
"ButtonCross: %u\n"
"ButtonCircle: %u\n"
"ShockButtonL: %u\n"
"ShockButtonR: %u\n"
"PedWalk: %u\n",
cs.LeftShoulder1, cs.LeftShoulder2, cs.RightShoulder1, cs.RightShoulder2, cs.DPadUp, cs.DPadDown, cs.DPadLeft, cs.DPadRight, cs.Start, cs.Select,
cs.ButtonSquare, cs.ButtonTriangle, cs.ButtonCross, cs.ButtonCircle, cs.ShockButtonL, cs.ShockButtonR, cs.m_bPedWalk);
g_pCore->GetGraphics()->DrawTextTTF(300, 10, 1280, 800, 0xFFFFFFFF, strBuffer, 1.0f, 0);
strBuffer = SString::Printf(
"VehicleMouseLook: %u\n"
"LeftStickX: %u\n"
"LeftStickY: %u\n"
"RightStickX: %u\n"
"RightStickY: %u",
cs.m_bVehicleMouseLook, cs.LeftStickX, cs.LeftStickY, cs.RightStickX, cs.RightStickY);
g_pCore->GetGraphics()->DrawTextTTF(300, 320, 1280, 800, 0xFFFFFFFF, strBuffer, 1.0f, 0);
#endif
UpdateModuleTickCount64();
if (m_pManager->IsGameLoaded())
{
// Pulse the nametags before anything that changes player positions, we'll be 1 frame behind, but so is the camera
// If nametags are enabled, pulse the nametag manager
if (m_bShowNametags)
{
m_pNametags->DoPulse();
}
// Sync debug
m_pSyncDebug->OnPulse();
// Also eventually draw FPS
if (m_bShowFPS)
{
DrawFPS();
}
CGraphicsInterface* pGraphics = g_pCore->GetGraphics();
unsigned int uiHeight = pGraphics->GetViewportHeight();
unsigned int uiWidth = pGraphics->GetViewportWidth();
// Draw a little star in the corner if async is on
if (g_pGame->IsASyncLoadingEnabled(true))
{
unsigned int uiPosY = g_pGame->IsASyncLoadingEnabled() ? uiHeight - 7 : uiHeight - 12;
pGraphics->DrawString(uiWidth - 5, uiPosY, 0x80ffffff, 1, "*");
}
// Draw notice text if dx test mode is enabled
if (g_pCore->GetGraphics()->GetRenderItemManager()->GetTestMode())
{
unsigned int uiPosY = uiHeight - 30;
pGraphics->DrawString(uiWidth - 155, uiPosY, 0x40ffffff, 1, "dx test mode enabled");
}
// Draw notice text if diagnostic mode enabled
EDiagnosticDebugType diagnosticDebug = g_pCore->GetDiagnosticDebug();
if (diagnosticDebug == EDiagnosticDebug::LOG_TIMING_0000)
{
unsigned int uiPosY = uiHeight - 30;
pGraphics->DrawString(uiWidth - 185, uiPosY, 0xffffff00, 1, "Debug setting: #0000 Log timing");
}
// Draw network trouble message if required
if (m_pNetAPI->IsNetworkTrouble())
{
int iPosX = uiWidth / 2; // Half way across
int iPosY = uiHeight * 45 / 100; // 45/100 down
g_pCore->GetGraphics()->DrawString(iPosX, iPosY, iPosX, iPosY, COLOR_ARGB(255, 255, 0, 0), "*** NETWORK TROUBLE ***", 2.0f, 2.0f,
DT_NOCLIP | DT_CENTER);
}
// Adjust the streaming memory size cvar [if needed]
if (!g_pCore->IsUsingCustomStreamingMemorySize())
{
unsigned int uiStreamingMemoryPrev;
g_pCore->GetCVars()->Get("streaming_memory", uiStreamingMemoryPrev);
uint uiStreamingMemory = SharedUtil::Clamp(g_pCore->GetMinStreamingMemory(), uiStreamingMemoryPrev, g_pCore->GetMaxStreamingMemory());
if (uiStreamingMemory != uiStreamingMemoryPrev)
g_pCore->GetCVars()->Set("streaming_memory", uiStreamingMemory);
}
const auto streamingMemorySizeBytes = g_pCore->GetStreamingMemory();
if (g_pMultiplayer->GetLimits()->GetStreamingMemory() != streamingMemorySizeBytes)
{
g_pMultiplayer->GetLimits()->SetStreamingMemory(streamingMemorySizeBytes);
}
// If we're in debug mode and are supposed to show task data, do it
#ifdef MTA_DEBUG
if (m_pShowPlayerTasks)
{
DrawTasks(m_pShowPlayerTasks);
}
if (m_pShowPlayer)
{
DrawPlayerDetails(m_pShowPlayer);
}
std::vector<CClientPlayer*>::const_iterator iter = m_pPlayerManager->IterBegin();
for (; iter != m_pPlayerManager->IterEnd(); ++iter)
{
CClientPlayer* pPlayer = *iter;
if (pPlayer->IsStreamedIn() && pPlayer->IsShowingWepdata())
DrawWeaponsyncData(pPlayer);
}
#endif
#if defined(MTA_DEBUG) || defined(MTA_BETA)
if (m_bShowSyncingInfo)
{
// Draw the header boxz
CVector vecPosition = CVector(0.05f, 0.32f, 0);
m_pDisplayManager->DrawText2D("Syncing vehicles:", vecPosition, 1.0f, 0xFFFFFFFF);
// Print each vehicle we're syncing
CDeathmatchVehicle* pVehicle;
list<CDeathmatchVehicle*>::const_iterator iter = m_pUnoccupiedVehicleSync->IterBegin();
for (; iter != m_pUnoccupiedVehicleSync->IterEnd(); iter++)
{
vecPosition.fY += 0.03f;
pVehicle = *iter;
SString strBuffer("ID: %u (%s)", pVehicle->GetID(), pVehicle->GetNamePointer());
m_pDisplayManager->DrawText2D(strBuffer, vecPosition, 1.0f, 0xFFFFFFFF);
}
}
#endif
// Heli Clear time
if (m_LastClearTime.Get() > HeliKill_List_Clear_Rate)
{
// Clear our list now
m_HeliCollisionsMap.clear();
m_LastClearTime.Reset();
}
// Check if we need to update the Discord Rich Presence state
if (const long long ticks = GetTickCount64_(); ticks > m_timeLastDiscordStateUpdate + TIME_DISCORD_UPDATE_RATE)
{
const auto discord = g_pCore->GetDiscord();