diff --git a/Client/core/CCore.cpp b/Client/core/CCore.cpp index 5cd37cefa6..6b734b6503 100644 --- a/Client/core/CCore.cpp +++ b/Client/core/CCore.cpp @@ -674,7 +674,7 @@ void CCore::SetConnected(bool bConnected) discord->SetPresenceDetails(""); if (bConnected) - discord->SetPresenceStartTimestamp(time(nullptr)); + discord->SetPresenceStartTimestamp(GetTickCount64_()); } } diff --git a/Client/core/CCore.h b/Client/core/CCore.h index fe4cb3c869..46203e7ad5 100644 --- a/Client/core/CCore.h +++ b/Client/core/CCore.h @@ -45,30 +45,30 @@ class CDiscordInterface; #define DIRECTINPUT_VERSION 0x0800 #include -#define BLUE_VERSION_STRING "Multi Theft Auto v" MTA_DM_BUILDTAG_LONG -#define BLUE_COPYRIGHT_STRING "Copyright (C) 2003 - %BUILD_YEAR% Multi Theft Auto" +#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 +#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; @@ -84,26 +84,26 @@ class CCore : public CCoreInterface, public CSingleton ~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 GetDiscord(); + 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 GetDiscord(); void SaveConfig(bool bWaitUntilFinished = false); @@ -286,8 +286,8 @@ class CCore : public CCoreInterface, public CSingleton bool IsUsingCustomStreamingMemorySize(); size_t GetStreamingMemory(); - SString GetLastConnectedServerName() const { return m_strLastConnectedServerName; } - void SetLastConnectedServerName(SString strServerName) { m_strLastConnectedServerName = strServerName; } + const SString& GetLastConnectedServerName() { return m_strLastConnectedServerName; } + void SetLastConnectedServerName(const SString& strServerName) { m_strLastConnectedServerName = strServerName; } private: void ApplyCoreInitSettings(); @@ -303,11 +303,11 @@ class CCore : public CCoreInterface, public CSingleton CModelCacheManager* m_pModelCacheManager; // Instances (put new classes here!) - CXMLFile* m_pConfigFile; - CClientVariables m_ClientVariables; - CWebCoreInterface* m_pWebCore = nullptr; - CTrayIcon* m_pTrayIcon; - std::shared_ptr m_pDiscordRichPresence; + CXMLFile* m_pConfigFile; + CClientVariables m_ClientVariables; + CWebCoreInterface* m_pWebCore = nullptr; + CTrayIcon* m_pTrayIcon; + std::shared_ptr m_pDiscordRichPresence; // Hook interfaces. CMessageLoopHook* m_pMessageLoopHook; @@ -373,22 +373,22 @@ class CCore : public CCoreInterface, public CSingleton EDiagnosticDebugType m_DiagnosticDebug; // Below 2 are used for the UI only - float m_fMinStreamingMemory{}; - float m_fMaxStreamingMemory{}; + 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; + 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{}; diff --git a/Client/core/CDiscordRichPresence.cpp b/Client/core/CDiscordRichPresence.cpp index 7ed9d44f8b..1edab1dd8c 100644 --- a/Client/core/CDiscordRichPresence.cpp +++ b/Client/core/CDiscordRichPresence.cpp @@ -140,13 +140,13 @@ void CDiscordRichPresence::SetAsset(const char* szAsset, const char* szAssetText { if (isLarge) { - m_strDiscordAppAsset = (std::string(szAsset).length() > 0 && szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET; - m_strDiscordAppAssetText = (std::string(szAssetText).length() > 0 && szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_TEXT; + m_strDiscordAppAsset = (std::strlen(szAsset) > 0 && szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET; + m_strDiscordAppAssetText = (std::strlen(szAssetText) > 0 && szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_TEXT; } else { - m_strDiscordAppAssetSmall = (std::string(szAsset).length() > 0 && szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET_SMALL; - m_strDiscordAppAssetSmallText = (std::string(szAssetText).length() > 0 && szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_SMALL_TEXT; + m_strDiscordAppAssetSmall = (std::strlen(szAsset) > 0 && szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET_SMALL; + m_strDiscordAppAssetSmallText = (std::strlen(szAssetText) > 0 && szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_SMALL_TEXT; } m_bUpdateRichPresence = true; } diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index 6b4b16c40c..3de43b5616 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -963,7 +963,7 @@ void CClientGame::DoPulsePostFrame() } // Check if we need to update the Discord Rich Presence state - if (time(nullptr) > m_timeLastDiscordStateUpdate + m_timeDiscordUpdateRate) + if (GetTickCount64_() > m_timeLastDiscordStateUpdate + m_timeDiscordUpdateRate) { auto discord = g_pCore->GetDiscord(); @@ -994,10 +994,10 @@ void CClientGame::DoPulsePostFrame() // Check for states which match our primary task std::vector taskStates{}; - for (auto it = g_playerTaskStates.begin(); it != g_playerTaskStates.end(); it++) + for (const auto& [task, state] : g_playerTaskStates) { - if (it->first == taskType) - taskStates.push_back(it->second); + if (task == taskType) + taskStates.push_back(state); } // Check for non-matching sub/secondary tasks and remove them @@ -1029,7 +1029,7 @@ void CClientGame::DoPulsePostFrame() int stateCount = taskStates.size(); if (stateCount > 0) { - std::srand(time(nullptr)); + std::srand(GetTickCount64_()); int index = (std::rand() % stateCount); auto taskState = taskStates[index]; @@ -1048,7 +1048,7 @@ void CClientGame::DoPulsePostFrame() discord->SetPresenceState("In-game", false); } - m_timeLastDiscordStateUpdate = time(nullptr); + m_timeLastDiscordStateUpdate = GetTickCount64_(); } } @@ -5653,8 +5653,10 @@ void CClientGame::DoWastedCheck(ElementID damagerID, unsigned char ucWeapon, uns auto discord = g_pCore->GetDiscord(); if (discord->IsDiscordRPCEnabled()) { - std::vector states{"In a ditch", "En-route to hospital", "Meeting their maker", "Regretting their decisions", "Wasted"}; - std::string state = states[rand() % states.size()]; + static const std::vector states{"In a ditch", "En-route to hospital", "Meeting their maker", "Regretting their decisions", + "Wasted"}; + + const std::string& state = states[rand() % states.size()]; discord->SetPresenceState(state.c_str(), false); } } diff --git a/Client/mods/deathmatch/logic/CClientGame.h b/Client/mods/deathmatch/logic/CClientGame.h index c688087d22..b330a45a2a 100644 --- a/Client/mods/deathmatch/logic/CClientGame.h +++ b/Client/mods/deathmatch/logic/CClientGame.h @@ -1,3 +1,4 @@ +/***************************************************************************** /***************************************************************************** * * PROJECT: Multi Theft Auto v1.0 @@ -45,8 +46,8 @@ #include "CSingularFileDownloadManager.h" #include "CObjectRespawner.h" -#define HeliKill_List_Clear_Rate 500 -#define MIN_PUSH_ANTISPAM_RATE 1500 +#define HeliKill_List_Clear_Rate 500 +#define MIN_PUSH_ANTISPAM_RATE 1500 #define INVALID_DOWNLOAD_PRIORITY_GROUP (INT_MIN) class CClientModelCacheManager; @@ -315,15 +316,15 @@ class CClientGame void ShowEaeg(bool bShow); void ShowFPS(bool bShow) { m_bShowFPS = bShow; }; - #if defined (MTA_DEBUG) || defined (MTA_BETA) +#if defined(MTA_DEBUG) || defined(MTA_BETA) void ShowSyncingInfo(bool bShow) { m_bShowSyncingInfo = bShow; }; - #endif +#endif #ifdef MTA_WEPSYNCDBG void ShowWepdata(const char* szNick); #endif - #ifdef MTA_DEBUG +#ifdef MTA_DEBUG void ShowWepdata(const char* szNick); void ShowTasks(const char* szNick); void ShowPlayer(const char* szNick); @@ -332,7 +333,7 @@ class CClientGame void SetDoPaintballs(bool bDoPaintballs) { m_bDoPaintballs = bDoPaintballs; } void ShowInterpolation(bool bShow) { m_bShowInterpolation = bShow; } bool IsShowingInterpolation() const { return m_bShowInterpolation; } - #endif +#endif CEntity* GetTargetedGameEntity() { return m_pTargetedGameEntity; } CClientEntity* GetTargetedEntity() { return m_pTargetedEntity; } @@ -476,17 +477,17 @@ class CClientGame void DrawFPS(); - #ifdef MTA_DEBUG +#ifdef MTA_DEBUG void DrawTasks(CClientPlayer* pPlayer); void DrawPlayerDetails(CClientPlayer* pPlayer); void UpdateMimics(); void DoPaintballs(); void DrawWeaponsyncData(CClientPlayer* pPlayer); - #endif +#endif - #ifdef MTA_WEPSYNCDBG +#ifdef MTA_WEPSYNCDBG void DrawWeaponsyncData(CClientPlayer* pPlayer); - #endif +#endif void DownloadSingularResourceFiles(); @@ -791,11 +792,11 @@ class CClientGame std::map m_CachedCollisionMap; bool m_BuiltCollisionMapThisFrame; - #if defined (MTA_DEBUG) || defined (MTA_BETA) +#if defined(MTA_DEBUG) || defined(MTA_BETA) bool m_bShowSyncingInfo; - #endif +#endif - #ifdef MTA_DEBUG +#ifdef MTA_DEBUG CClientPlayer* m_pShowPlayerTasks; CClientPlayer* m_pShowPlayer; std::list m_Mimics; @@ -807,10 +808,10 @@ class CClientGame CVector m_vecLastMimicRot; bool m_bDoPaintballs; bool m_bShowInterpolation; - #endif - bool m_bDevelopmentMode; - bool m_bShowCollision; - bool m_bShowSound; +#endif + bool m_bDevelopmentMode; + bool m_bShowCollision; + bool m_bShowSound; // Debug class. Empty in release. public: @@ -850,7 +851,7 @@ class CClientGame RunNamedAnimTask_type m_mapOfRunNamedAnimTasks; const time_t m_timeDiscordUpdateRate = 15; - time_t m_timeLastDiscordStateUpdate; + time_t m_timeLastDiscordStateUpdate; }; extern CClientGame* g_pClientGame; diff --git a/Client/mods/deathmatch/logic/CClientVehicle.h b/Client/mods/deathmatch/logic/CClientVehicle.h index e57176e5d7..fcdfeb6481 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.h +++ b/Client/mods/deathmatch/logic/CClientVehicle.h @@ -49,6 +49,8 @@ enum eClientVehicleType CLIENTVEHICLE_TRAILER }; +static constexpr int NUM_VEHICLE_TYPES = 11; + enum eDelayedSyncVehicleData { DELAYEDSYNC_VEHICLE_KEYSYNC, @@ -145,11 +147,9 @@ struct SVehicleComponentData bool m_bVisible; }; -static const std::map g_vehicleTypePrefixes{ - {CLIENTVEHICLE_CAR, "Cruising around"}, {CLIENTVEHICLE_PLANE, "Flying around"}, {CLIENTVEHICLE_BIKE, "Riding around"}, - {CLIENTVEHICLE_HELI, "Flying around"}, {CLIENTVEHICLE_BOAT, "Riding the waves of"}, {CLIENTVEHICLE_TRAIN, "Riding the train in"}, - {CLIENTVEHICLE_TRAILER, "Doing weird stuff in"}, {CLIENTVEHICLE_BMX, "Bunny hopping around"}, {CLIENTVEHICLE_MONSTERTRUCK, "Monster truckin' around"}, - {CLIENTVEHICLE_QUADBIKE, "Quaddin' around"}}; +static const std::array g_vehicleTypePrefixes = { + "Flying a UFO around", "Cruising around", "Flying around", "Riding around", "Flying around", "Riding the waves of", + "Riding the train in", "Doing weird stuff in", "Bunny hopping around", "Monster truckin' around", "Quaddin' around"}; class CClientVehicle : public CClientStreamElement { diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp index 92980ade58..9d36c8e445 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp @@ -123,7 +123,7 @@ bool CLuaDiscordDefs::SetDetails(std::string strDetails) bool CLuaDiscordDefs::SetStartTime(unsigned long ulTime) { - unsigned long ulSecondsSinceEpoch = time(nullptr) + ulTime; + unsigned long ulSecondsSinceEpoch = GetTickCount64_() + ulTime; if (ulTime == 0) ulSecondsSinceEpoch = 0; @@ -142,7 +142,7 @@ bool CLuaDiscordDefs::SetStartTime(unsigned long ulTime) bool CLuaDiscordDefs::SetEndTime(unsigned long ulTime) { - unsigned long ulSecondsSinceEpoch = time(nullptr) + ulTime; + unsigned long ulSecondsSinceEpoch = GetTickCount64_() + ulTime; if (ulTime == 0) ulSecondsSinceEpoch = 0; diff --git a/Client/sdk/core/CCoreInterface.h b/Client/sdk/core/CCoreInterface.h index ea45c77300..ee9b128fe1 100644 --- a/Client/sdk/core/CCoreInterface.h +++ b/Client/sdk/core/CCoreInterface.h @@ -41,17 +41,21 @@ enum eCoreVersion }; #ifndef WITH_TIMING_CHECKPOINTS - #define WITH_TIMING_CHECKPOINTS 1 // Comment this line to remove timing checkpoint code + #define WITH_TIMING_CHECKPOINTS 1 // Comment this line to remove timing checkpoint code #endif #if WITH_TIMING_CHECKPOINTS - #define IS_TIMING_CHECKPOINTS() g_pCore->IsTimingCheckpoints () - #define TIMING_CHECKPOINT(x) g_pCore->OnTimingCheckpoint ( x ) - #define TIMING_DETAIL(x) g_pCore->OnTimingDetail ( x ) + #define IS_TIMING_CHECKPOINTS() g_pCore->IsTimingCheckpoints() + #define TIMING_CHECKPOINT(x) g_pCore->OnTimingCheckpoint(x) + #define TIMING_DETAIL(x) g_pCore->OnTimingDetail(x) #else - #define IS_TIMING_CHECKPOINTS() (false) - #define TIMING_CHECKPOINT(x) {} - #define TIMING_DETAIL(x) {} + #define IS_TIMING_CHECKPOINTS() (false) + #define TIMING_CHECKPOINT(x) \ + { \ + } + #define TIMING_DETAIL(x) \ + { \ + } #endif class CCoreInterface @@ -61,22 +65,22 @@ class CCoreInterface // correct MTA version before trying to use any other interface funcs. virtual eCoreVersion GetVersion() = 0; - virtual CConsoleInterface* GetConsole() = 0; - virtual CCommandsInterface* GetCommands() = 0; - virtual CGame* GetGame() = 0; - virtual CGraphicsInterface* GetGraphics() = 0; - virtual CGUI* GetGUI() = 0; - virtual CModManagerInterface* GetModManager() = 0; - virtual CMultiplayer* GetMultiplayer() = 0; - virtual CNet* GetNetwork() = 0; - virtual CXML* GetXML() = 0; - virtual CKeyBindsInterface* GetKeyBinds() = 0; - virtual CXMLNode* GetConfig() = 0; - virtual CCVarsInterface* GetCVars() = 0; - virtual CLocalizationInterface* GetLocalization() = 0; - virtual CWebCoreInterface* GetWebCore() = 0; - virtual CTrayIconInterface* GetTrayIcon() = 0; - virtual std::shared_ptr GetDiscord() = 0; + virtual CConsoleInterface* GetConsole() = 0; + virtual CCommandsInterface* GetCommands() = 0; + virtual CGame* GetGame() = 0; + virtual CGraphicsInterface* GetGraphics() = 0; + virtual CGUI* GetGUI() = 0; + virtual CModManagerInterface* GetModManager() = 0; + virtual CMultiplayer* GetMultiplayer() = 0; + virtual CNet* GetNetwork() = 0; + virtual CXML* GetXML() = 0; + virtual CKeyBindsInterface* GetKeyBinds() = 0; + virtual CXMLNode* GetConfig() = 0; + virtual CCVarsInterface* GetCVars() = 0; + virtual CLocalizationInterface* GetLocalization() = 0; + virtual CWebCoreInterface* GetWebCore() = 0; + virtual CTrayIconInterface* GetTrayIcon() = 0; + virtual std::shared_ptr GetDiscord() = 0; // Temporary functions for r1 virtual void DebugEcho(const char* szText) = 0; @@ -186,8 +190,8 @@ class CCoreInterface virtual bool IsUsingCustomStreamingMemorySize() = 0; virtual size_t GetStreamingMemory() = 0; - virtual SString GetLastConnectedServerName() const = 0; - virtual void SetLastConnectedServerName(SString strServerName) = 0; + virtual const SString& GetLastConnectedServerName() = 0; + virtual void SetLastConnectedServerName(const SString& strServerName) = 0; }; class CClientTime