/
CCore.h
401 lines (343 loc) · 16.9 KB
/
CCore.h
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
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: core/CCore.h
* PURPOSE: Header file for base core class
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/
class CCore;
class CDiscordRichPresence;
class CDiscordInterface;
#pragma once
#include "version.h"
#include "CClientVariables.h"
#include "CCommands.h"
#include "CModuleLoader.h"
#include "CSingleton.h"
#include "CGUI.h"
#include "CConnectManager.h"
#include <DXHook/CDirect3DHookManager.h>
#include <DXHook/CDirectInputHookManager.h>
#include <Graphics/CGraphics.h>
#include "CSetCursorPosHook.h"
#include "CMessageLoopHook.h"
#include "CConsoleLogger.h"
#include "CModManager.h"
#include <core/CClientEntityBase.h>
#include <core/CCoreInterface.h>
#include <DXHook/CDirect3DData.h>
#include "CClientVariables.h"
#include "CKeyBinds.h"
#include "CMouseControl.h"
#include "CScreenShot.h"
#include <xml/CXML.h>
#include <ijsify.h>
#include <core/CWebCoreInterface.h>
#include "CTrayIcon.h"
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#define BLUE_VERSION_STRING "Multi Theft Auto v" MTA_DM_BUILDTAG_LONG
#define BLUE_COPYRIGHT_STRING "Copyright (C) 2003 - %BUILD_YEAR% Multi Theft Auto"
// Configuration file path (relative to MTA install directory)
#define MTA_CONFIG_PATH "mta/config/coreconfig.xml"
#define MTA_SERVER_CACHE_PATH "mta/config/servercache.xml"
#define MTA_CONSOLE_LOG_PATH "mta/logs/console.log"
#define MTA_CONSOLE_INPUT_LOG_PATH "mta/logs/console-input.log"
#define CONFIG_ROOT "mainconfig"
#define CONFIG_NODE_CVARS "settings" // cvars node
#define CONFIG_NODE_KEYBINDS "binds" // keybinds node
#define CONFIG_NODE_JOYPAD "joypad"
#define CONFIG_NODE_UPDATER "updater"
#define CONFIG_NODE_SERVER_INT "internet_servers" // backup of last successful master server list query
#define CONFIG_NODE_SERVER_FAV "favourite_servers" // favourite servers list node
#define CONFIG_NODE_SERVER_REC "recently_played_servers" // recently played servers list node
#define CONFIG_NODE_SERVER_OPTIONS "serverbrowser_options" // saved options for the server browser
#define CONFIG_NODE_SERVER_SAVED "server_passwords" // This contains saved passwords (as appose to save_server_passwords which is a setting)
#define CONFIG_NODE_SERVER_HISTORY "connect_history"
#define CONFIG_INTERNET_LIST_TAG "internet_server"
#define CONFIG_FAVOURITE_LIST_TAG "favourite_server"
#define CONFIG_RECENT_LIST_TAG "recently_played_server"
#define CONFIG_HISTORY_LIST_TAG "connected_server"
#define IDT_TIMER1 1234
extern class CCore* g_pCore;
extern class CGraphics* g_pGraphics;
extern class CLocalization* g_pLocalization;
bool UsingAltD3DSetup();
extern SString g_strJingleBells;
class CCore : public CCoreInterface, public CSingleton<CCore>
{
public:
ZERO_ON_NEW
CCore();
~CCore();
// Subsystems (query)
eCoreVersion GetVersion();
CConsoleInterface* GetConsole();
CCommandsInterface* GetCommands();
CConnectManager* GetConnectManager() { return m_pConnectManager; };
CGame* GetGame();
CGUI* GetGUI();
CGraphicsInterface* GetGraphics();
CModManagerInterface* GetModManager();
CMultiplayer* GetMultiplayer();
CNet* GetNetwork();
CXML* GetXML() { return m_pXML; };
CXMLNode* GetConfig();
CClientVariables* GetCVars() { return &m_ClientVariables; };
CKeyBindsInterface* GetKeyBinds();
CMouseControl* GetMouseControl() { return m_pMouseControl; };
CLocalGUI* GetLocalGUI();
CLocalizationInterface* GetLocalization() { return g_pLocalization; };
CWebCoreInterface* GetWebCore();
CTrayIconInterface* GetTrayIcon() { return m_pTrayIcon; };
std::shared_ptr<CDiscordInterface> GetDiscord();
void SaveConfig(bool bWaitUntilFinished = false);
// Debug
void DebugEcho(const char* szText);
void DebugPrintf(const char* szFormat, ...);
void SetDebugVisible(bool bVisible);
bool IsDebugVisible();
void DebugEchoColor(const char* szText, unsigned char R, unsigned char G, unsigned char B);
void DebugPrintfColor(const char* szFormat, unsigned char R, unsigned char G, unsigned char B, ...);
void DebugClear();
// Chat
void ChatEcho(const char* szText, bool bColorCoded = false);
void ChatEchoColor(const char* szText, unsigned char R, unsigned char G, unsigned char B, bool bColorCoded = false);
void ChatPrintf(const char* szFormat, bool bColorCoded, ...);
void ChatPrintfColor(const char* szFormat, bool bColorCoded, unsigned char R, unsigned char G, unsigned char B, ...);
void SetChatVisible(bool bVisible, bool bInputBlocked);
bool IsChatVisible();
bool IsChatInputBlocked();
void EnableChatInput(char* szCommand, DWORD dwColor);
bool IsChatInputEnabled();
bool ClearChat();
void OnGameTimerUpdate();
bool SetChatboxCharacterLimit(int charLimit);
void ResetChatboxCharacterLimit();
int GetChatboxCharacterLimit();
int GetChatboxMaxCharacterLimit();
// Screenshot
void InitiateScreenShot(bool bIsCameraShot);
// GUI
bool IsSettingsVisible();
bool IsMenuVisible();
bool IsCursorForcedVisible();
bool IsCursorControlsToggled() { return m_bCursorToggleControls; }
void HideMainMenu();
void SetCenterCursor(bool bEnabled);
void ShowServerInfo(unsigned int WindowType);
// Configuration
void ApplyConsoleSettings();
void ApplyGameSettings();
void UpdateRecentlyPlayed();
// Net
void SetConnected(bool bConnected);
bool IsConnected();
bool Reconnect(const char* szHost, unsigned short usPort, const char* szPassword, bool bSave = true);
// Mod
void SetOfflineMod(bool bOffline);
void ForceCursorVisible(bool bVisible, bool bToggleControls = true);
void SetMessageProcessor(pfnProcessMessage pfnMessageProcessor);
void ShowMessageBox(const char* szTitle, const char* szText, unsigned int uiFlags, GUI_CALLBACK* ResponseHandler = NULL);
void RemoveMessageBox(bool bNextFrame = false);
void ShowErrorMessageBox(const SString& strTitle, SString strMessage, const SString& strTroubleLink = "");
void ShowNetErrorMessageBox(const SString& strTitle, SString strMessage, SString strTroubleLink = "", bool bLinkRequiresErrorCode = false);
static void ErrorMessageBoxCallBack(void* pData, uint uiButton);
bool IsOfflineMod() { return m_bIsOfflineMod; }
const char* GetModInstallRoot(const char* szModName);
bool CheckDiskSpace(uint uiResourcesPathMinMB = 10, uint uiDataPathMinMB = 10);
// Subsystems
void CreateGame();
void CreateMultiplayer();
void CreateNetwork();
void CreateXML();
void InitGUI(IDirect3DDevice9* pDevice);
void CreateGUI();
void DestroyGame();
void DestroyMultiplayer();
void DestroyNetwork();
void DestroyXML();
void DeinitGUI();
void DestroyGUI();
// Web
bool IsWebCoreLoaded() { return m_pWebCore != nullptr; }
void DestroyWeb();
// Hooks
void ApplyHooks();
void ApplyHooks2();
void ApplyHooks3(bool bEnable);
HWND GetHookedWindow();
void SwitchRenderWindow(HWND hWnd, HWND hWndInput);
void CallSetCursorPos(int X, int Y);
void SetClientMessageProcessor(pfnProcessMessage pfnMessageProcessor) { m_pfnMessageProcessor = pfnMessageProcessor; };
pfnProcessMessage GetClientMessageProcessor() { return m_pfnMessageProcessor; }
void ChangeResolution(long width, long height, long depth);
bool IsFocused() { return (GetForegroundWindow() == GetHookedWindow()); };
bool IsWindowMinimized();
void UpdateIsWindowMinimized();
// Pulse
void DoPreFramePulse();
void DoPostFramePulse();
// Events
void OnModUnload();
// Misc
void RegisterCommands();
bool IsValidNick(const char* szNick); // Move somewhere else
void Quit(bool bInstantly = true);
void InitiateUpdate(const char* szType, const char* szData, const char* szHost) { m_pLocalGUI->InitiateUpdate(szType, szData, szHost); }
bool IsOptionalUpdateInfoRequired(const char* szHost) { return m_pLocalGUI->IsOptionalUpdateInfoRequired(szHost); }
void InitiateDataFilesFix() { m_pLocalGUI->InitiateDataFilesFix(); }
uint GetFrameRateLimit() { return m_uiFrameRateLimit; }
void RecalculateFrameRateLimit(uint uiServerFrameRateLimit = -1, bool bLogToConsole = true);
void ApplyFrameRateLimit(uint uiOverrideRate = -1);
void ApplyQueuedFrameRateLimit();
void EnsureFrameRateLimitApplied();
void SetClientScriptFrameRateLimit(uint uiClientScriptFrameRateLimit);
void DoReliablePulse();
bool IsTimingCheckpoints();
void OnTimingCheckpoint(const char* szTag);
void OnTimingDetail(const char* szTag);
void CalculateStreamingMemoryRange();
uint GetMinStreamingMemory();
uint GetMaxStreamingMemory();
SString GetConnectCommandFromURI(const char* szURI);
void GetConnectParametersFromURI(const char* szURI, std::string& strHost, unsigned short& usPort, std::string& strNick, std::string& strPassword);
std::map<std::string, std::string>& GetCommandLineOptions() { return m_CommandLineOptions; }
const char* GetCommandLineOption(const char* szOption);
const char* GetCommandLineArgs() { return m_szCommandLineArgs; }
void RequestNewNickOnStart() { m_bWaitToSetNick = true; };
bool WillRequestNewNickOnStart() { return m_bWaitToSetNick; };
bool WasLaunchedWithConnectURI();
void HandleCrashDumpEncryption();
void OnPreFxRender();
void OnPreHUDRender();
void OnDeviceRestore();
void OnCrashAverted(uint uiId);
void OnEnterCrashZone(uint uiId);
void LogEvent(uint uiDebugId, const char* szType, const char* szContext, const char* szBody, uint uiAddReportLogId = 0);
bool GetDebugIdEnabled(uint uiDebugId);
EDiagnosticDebugType GetDiagnosticDebug();
void SetDiagnosticDebug(EDiagnosticDebugType value);
CModelCacheManager* GetModelCacheManager();
void AddModelToPersistentCache(ushort usModelId);
static void StaticIdleHandler();
void IdleHandler();
void WindowsTimerHandler();
void HandleIdlePulse();
void SetModulesLoaded(bool bLoaded);
bool AreModulesLoaded();
void UpdateDummyProgress(int iValue = -1, const char* szType = "");
void SetDummyProgressUpdateAlways(bool bAlways) { m_bDummyProgressUpdateAlways = bAlways; }
bool GetDummyProgressUpdateAlways() { return m_bDummyProgressUpdateAlways; }
void OnPreCreateDevice(IDirect3D9* pDirect3D, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD& BehaviorFlags,
D3DPRESENT_PARAMETERS* pPresentationParameters);
HRESULT OnPostCreateDevice(HRESULT hResult, IDirect3D9* pDirect3D, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags,
D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface);
bool GetDeviceSelectionEnabled();
bool GetRequiredDisplayResolution(int& iOutWidth, int& iOutHeight, int& iOutColorBits, int& iOutAdapterIndex, bool& bOutAllowUnsafeResolutions);
void NotifyRenderingGrass(bool bIsRenderingGrass);
bool IsRenderingGrass() { return m_bIsRenderingGrass; }
bool GetRightSizeTxdEnabled();
const char* GetProductRegistryPath() { return SharedUtil::GetProductRegistryPath(); }
const char* GetProductCommonDataDir() { return SharedUtil::GetProductCommonDataDir(); }
const char* GetProductVersion() { return SharedUtil::GetProductVersion(); }
void SetFakeLagCommandEnabled(bool bEnabled) { m_bFakeLagCommandEnabled = bEnabled; }
bool IsFakeLagCommandEnabled() { return m_bFakeLagCommandEnabled; }
SString GetBlueCopyrightString();
bool IsFirstFrame() const noexcept { return m_bFirstFrame; }
void SetCustomStreamingMemory(size_t szMB);
bool IsUsingCustomStreamingMemorySize();
size_t GetStreamingMemory();
const SString& GetLastConnectedServerName() const { return m_strLastConnectedServerName; }
void SetLastConnectedServerName(const SString& strServerName) { m_strLastConnectedServerName = strServerName; }
private:
void ApplyCoreInitSettings();
private:
// Core devices.
CXML* m_pXML;
CLocalGUI* m_pLocalGUI;
CGraphics* m_pGraphics;
CCommands* m_pCommands;
CDirect3DData* m_pDirect3DData;
CConnectManager* m_pConnectManager;
CModelCacheManager* m_pModelCacheManager;
// Instances (put new classes here!)
CXMLFile* m_pConfigFile;
CClientVariables m_ClientVariables;
CWebCoreInterface* m_pWebCore = nullptr;
CTrayIcon* m_pTrayIcon;
std::shared_ptr<CDiscordRichPresence> m_pDiscordRichPresence;
// Hook interfaces.
CMessageLoopHook* m_pMessageLoopHook;
CDirectInputHookManager* m_pDirectInputHookManager;
CDirect3DHookManager* m_pDirect3DHookManager;
// CFileSystemHook * m_pFileSystemHook;
CSetCursorPosHook* m_pSetCursorPosHook;
bool m_bLastFocused;
int m_iUnminimizeFrameCounter;
bool m_bDidRecreateRenderTargets;
bool m_bIsWindowMinimized;
// Module loader objects.
CModuleLoader m_GameModule;
CModuleLoader m_MultiplayerModule;
CModuleLoader m_NetModule;
CModuleLoader m_XMLModule;
CModuleLoader m_GUIModule;
CModuleLoader m_WebCoreModule;
// Mod manager
CModManager* m_pModManager;
// Module interfaces.
CGame* m_pGame;
CNet* m_pNet;
CMultiplayer* m_pMultiplayer;
CGUI* m_pGUI;
// Logger utility interface.
CConsoleLogger* m_pConsoleLogger;
CLocalization* m_pLocalization;
CKeyBinds* m_pKeyBinds;
CMouseControl* m_pMouseControl;
bool m_bFirstFrame;
bool m_bIsOfflineMod;
bool m_bCursorToggleControls;
pfnProcessMessage m_pfnMessageProcessor;
CGUIMessageBox* m_pMessageBox;
// screen res
DEVMODE m_Current;
SString m_strModInstallRoot;
bool m_bQuitOnPulse;
bool m_bDestroyMessageBox;
bool m_bDoneFrameRateLimit;
uint m_uiServerFrameRateLimit;
uint m_uiClientScriptFrameRateLimit;
uint m_uiFrameRateLimit;
CElapsedTimeHD m_FrameRateTimer;
uint m_uiQueuedFrameRate;
bool m_bQueuedFrameRateValid;
bool m_bWaitToSetNick;
uint m_uiNewNickWaitFrames;
EDiagnosticDebugType m_DiagnosticDebug;
// Below 2 are used for the UI only
float m_fMinStreamingMemory{};
float m_fMaxStreamingMemory{};
// Custom streaming memory limit set by `engineStreamingSetMemorySize` - Reset on server connects (= set to 0), or by the scripter
// `0` means "not set" [so the value should be ignored]
size_t m_CustomStreamingMemoryLimitBytes{};
bool m_bGettingIdleCallsFromMultiplayer;
bool m_bWindowsTimerEnabled;
bool m_bModulesLoaded;
int m_iDummyProgressValue;
HANDLE m_DummyProgressTimerHandle;
SString m_strDummyProgressType;
bool m_bDummyProgressUpdateAlways;
bool m_bIsRenderingGrass;
bool m_bFakeLagCommandEnabled;
SString m_strLastConnectedServerName{};
// Command line
static void ParseCommandLine(std::map<std::string, std::string>& options, const char*& szArgs, const char** pszNoValOptions = NULL);
std::map<std::string, std::string> m_CommandLineOptions; // e.g. "-o option" -> {"o" = "option"}
const char* m_szCommandLineArgs; // Everything that comes after the options
long long m_timeDiscordAppLastUpdate;
};