Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/clump_atomic_models
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX authored Mar 9, 2025
2 parents 2d6b43b + 469246f commit 1384b37
Show file tree
Hide file tree
Showing 20 changed files with 454 additions and 515 deletions.
2 changes: 1 addition & 1 deletion Client/cefweb/CWebCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ std::unordered_set<SString> CWebCore::AllowPendingPages(bool bRemember)
}

// Trigger an event now
auto pCurrentMod = g_pCore->GetModManager()->GetCurrentMod();
auto pCurrentMod = g_pCore->GetModManager()->GetClient();
if (!pCurrentMod)
return std::unordered_set<SString>();

Expand Down
4 changes: 2 additions & 2 deletions Client/core/CChat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,11 @@ bool CChat::CharacterKeyHandler(CGUIKeyEventArgs KeyboardArgs)
SString strPlayerNamePart = strCurrentInput.substr(iFound);

CModManager* pModManager = CModManager::GetSingletonPtr();
if (pModManager && pModManager->GetCurrentMod())
if (pModManager && pModManager->IsLoaded())
{
// Create vector and get playernames from deathmatch module
std::vector<SString> vPlayerNames;
pModManager->GetCurrentMod()->GetPlayerNames(vPlayerNames);
pModManager->GetClient()->GetPlayerNames(vPlayerNames);

for (std::vector<SString>::iterator iter = vPlayerNames.begin(); iter != vPlayerNames.end(); ++iter)
{
Expand Down
45 changes: 17 additions & 28 deletions Client/core/CCommandFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,36 +167,13 @@ void CCommandFuncs::Clear(const char* szParameters)

void CCommandFuncs::Load(const char* szParameters)
{
if (!szParameters)
{
CCore::GetSingleton().GetConsole()->Printf("* Syntax: load <mod-name> [<arguments>]");
return;
}

// Copy the buffer
char* szTemp = new char[strlen(szParameters) + 1];
strcpy(szTemp, szParameters);

// Split it up into mod name and the arguments
char* szModName = strtok(szTemp, " ");
char* szArguments = strtok(NULL, "\0");

if (szModName)
{
// Load the mod with the given arguments
CModManager::GetSingleton().RequestLoad(szModName, szArguments);
}
else
CCore::GetSingleton().GetConsole()->Printf("* Syntax: load <mod-name> [<arguments>]");

// Free the temp buffer
delete[] szTemp;
CModManager::GetSingleton().RequestLoad(szParameters);
}

void CCommandFuncs::Unload(const char* szParameters)
{
// Any mod loaded?
if (CModManager::GetSingleton().GetCurrentMod())
if (CModManager::GetSingleton().IsLoaded())
{
// Unload it
CModManager::GetSingleton().RequestUnload();
Expand All @@ -209,6 +186,12 @@ void CCommandFuncs::Unload(const char* szParameters)

void CCommandFuncs::Connect(const char* szParameters)
{
if (!CCore::GetSingleton().IsNetworkReady())
{
CCore::GetSingleton().GetConsole()->Print(_("connect: Network is not ready, please wait a moment"));
return;
}

// Parse the arguments (host port nick pass)
char szBuffer[256] = "";
if (szParameters)
Expand Down Expand Up @@ -264,7 +247,7 @@ void CCommandFuncs::Connect(const char* szParameters)
CModManager::GetSingleton().Unload();

// Only connect if there is no mod loaded
if (!CModManager::GetSingleton().GetCurrentMod())
if (!CModManager::GetSingleton().IsLoaded())
{
// Start the connect
if (CCore::GetSingleton().GetConnectManager()->Connect(szHost, usPort, strNick.c_str(), szPass))
Expand All @@ -284,7 +267,7 @@ void CCommandFuncs::Connect(const char* szParameters)

void CCommandFuncs::ReloadNews(const char* szParameters)
{
if (CModManager::GetSingleton().GetCurrentMod())
if (CModManager::GetSingleton().IsLoaded())
{
CCore::GetSingleton().GetConsole()->Print("reloadnews: can't do this whilst connected to server");
return;
Expand All @@ -296,6 +279,12 @@ void CCommandFuncs::ReloadNews(const char* szParameters)

void CCommandFuncs::Reconnect(const char* szParameters)
{
if (!CCore::GetSingleton().IsNetworkReady())
{
CCore::GetSingleton().GetConsole()->Print(_("reconnect: Network is not ready, please wait a moment"));
return;
}

CModManager::GetSingleton().Unload();

std::string strHost, strNick, strPassword;
Expand All @@ -309,7 +298,7 @@ void CCommandFuncs::Reconnect(const char* szParameters)
CModManager::GetSingleton().Unload();

// Any mod loaded?
if (!CModManager::GetSingleton().GetCurrentMod())
if (!CModManager::GetSingleton().IsLoaded())
{
// Verify and convert the port number
if (uiPort <= 0 || uiPort > 0xFFFF)
Expand Down
21 changes: 15 additions & 6 deletions Client/core/CConnectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ bool CConnectManager::Connect(const char* szHost, unsigned short usPort, const c
assert(szNick);
assert(szPassword);

if (!CCore::GetSingleton().IsNetworkReady())
{
CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->ShowNetworkNotReadyWindow();
return false;
}

m_bNotifyServerBrowser = bNotifyServerBrowser;

// For detecting startup problems
Expand Down Expand Up @@ -337,10 +343,13 @@ void CConnectManager::DoPulse()
}
else if (m_bReconnect)
{
std::string strNick;
CVARS_GET("nick", strNick);
Connect(m_strHost.c_str(), m_usPort, strNick.c_str(), m_strPassword.c_str(), false);
m_bReconnect = false;
if (CCore::GetSingleton().IsNetworkReady())
{
std::string strNick;
CVARS_GET("nick", strNick);
Connect(m_strHost.c_str(), m_usPort, strNick.c_str(), m_strPassword.c_str(), false);
m_bReconnect = false;
}
}
}

Expand All @@ -364,7 +373,7 @@ bool CConnectManager::StaticProcessPacket(unsigned char ucPacketID, NetBitStream
// Process packet data
CCore::GetSingleton().GetNetwork()->SetServerBitStreamVersion(usServerBitStreamVersion);

if (strModName != "")
if (strModName == "deathmatch")
{
// Populate the arguments to pass it (-c host port nick)
SString strArguments("%s %s", g_pConnectManager->m_strNick.c_str(), g_pConnectManager->m_strPassword.c_str());
Expand Down Expand Up @@ -399,7 +408,7 @@ bool CConnectManager::StaticProcessPacket(unsigned char ucPacketID, NetBitStream
g_pConnectManager->m_tConnectStarted = 0;

// Load the mod
if (!CModManager::GetSingleton().Load(strModName, strArguments))
if (!CModManager::GetSingleton().Load(strArguments))
{
// Failed loading the mod
strArguments.Format(_("No such mod installed (%s)"), strModName.c_str());
Expand Down
59 changes: 29 additions & 30 deletions Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ CCore::CCore()
m_pfnMessageProcessor = NULL;
m_pMessageBox = NULL;

m_bFirstFrame = true;
m_bIsOfflineMod = false;
m_bQuitOnPulse = false;
m_bDestroyMessageBox = false;
m_bCursorToggleControls = false;
m_bLastFocused = true;
m_bWaitToSetNick = false;
m_DiagnosticDebug = EDiagnosticDebug::NONE;

// Create our Direct3DData handler.
Expand Down Expand Up @@ -151,14 +149,14 @@ CCore::CCore()
m_bDoneFrameRateLimit = false;
m_uiFrameRateLimit = 0;
m_uiServerFrameRateLimit = 0;
m_uiNewNickWaitFrames = 0;
m_iUnminimizeFrameCounter = 0;
m_bDidRecreateRenderTargets = false;
m_fMinStreamingMemory = 0;
m_fMaxStreamingMemory = 0;
m_bGettingIdleCallsFromMultiplayer = false;
m_bWindowsTimerEnabled = false;
m_timeDiscordAppLastUpdate = 0;
m_CurrentRefreshRate = 60;

// Create tray icon
m_pTrayIcon = new CTrayIcon();
Expand Down Expand Up @@ -515,7 +513,7 @@ void CCore::EnableChatInput(char* szCommand, DWORD dwColor)
{
if (m_pLocalGUI)
{
if (m_pGame->GetSystemState() == 9 /* GS_PLAYING_GAME */ && m_pModManager->GetCurrentMod() != NULL && !IsOfflineMod() && !m_pGame->IsAtMenu() &&
if (m_pGame->GetSystemState() == 9 /* GS_PLAYING_GAME */ && m_pModManager->IsLoaded() && !IsOfflineMod() && !m_pGame->IsAtMenu() &&
!m_pLocalGUI->GetMainMenu()->IsVisible() && !m_pLocalGUI->GetConsole()->IsVisible() && !m_pLocalGUI->IsChatBoxInputEnabled())
{
CChat* pChat = m_pLocalGUI->GetChat();
Expand Down Expand Up @@ -1236,16 +1234,22 @@ void CCore::DoPostFramePulse()
// This is the first frame in the menu?
if (m_pGame->GetSystemState() == 7) // GS_FRONTEND
{
if (m_bFirstFrame)
{
m_bFirstFrame = false;
if (m_menuFrame < 255)
++m_menuFrame;

if (m_menuFrame == 1)
{
WatchDogCompletedSection("L2"); // gta_sa.set seems ok
WatchDogCompletedSection("L3"); // No hang on startup
HandleCrashDumpEncryption();

// Disable vsync while it's all dark
m_pGame->DisableVSync();
}

if (m_menuFrame >= 5 && !m_isNetworkReady && m_pNet->IsReady())
{
m_isNetworkReady = true;

// Parse the command line
// Does it begin with mtasa://?
Expand All @@ -1262,33 +1266,18 @@ void CCore::DoPostFramePulse()
{
// We want to load a mod?
const char* szOptionValue;
if (szOptionValue = GetCommandLineOption("l"))
{
// Try to load the mod
if (!m_pModManager->Load(szOptionValue, m_szCommandLineArgs))
{
SString strTemp(_("Error running mod specified in command line ('%s')"), szOptionValue);
ShowMessageBox(_("Error") + _E("CC42"), strTemp, MB_BUTTON_OK | MB_ICON_ERROR); // Command line Mod load failed
}
}
// We want to connect to a server?
else if (szOptionValue = GetCommandLineOption("c"))
if (szOptionValue = GetCommandLineOption("c"))
{
CCommandFuncs::Connect(szOptionValue);
}
}
}

if (m_bWaitToSetNick && GetLocalGUI()->GetMainMenu()->IsVisible() && !GetLocalGUI()->GetMainMenu()->IsFading())
if (m_menuFrame >= 75 && m_requestNewNickname && GetLocalGUI()->GetMainMenu()->IsVisible() && !GetLocalGUI()->GetMainMenu()->IsFading())
{
if (m_uiNewNickWaitFrames > 75)
{
// Request a new nickname if we're waiting for one
GetLocalGUI()->GetMainMenu()->GetSettingsWindow()->RequestNewNickname();
m_bWaitToSetNick = false;
}
else
m_uiNewNickWaitFrames++;
// Request a new nickname if we're waiting for one
GetLocalGUI()->GetMainMenu()->GetSettingsWindow()->RequestNewNickname();
m_requestNewNickname = false;
}
}

Expand Down Expand Up @@ -1847,6 +1836,9 @@ void CCore::RecalculateFrameRateLimit(uint uiServerFrameRateLimit, bool bLogToCo
if ((m_uiFrameRateLimit == 0 || uiClientScriptRate < m_uiFrameRateLimit) && uiClientScriptRate > 0)
m_uiFrameRateLimit = uiClientScriptRate;

if (!IsConnected())
m_uiFrameRateLimit = m_CurrentRefreshRate;

// Removes Limiter from Frame Graph if limit is zero and skips frame limit
if (m_uiFrameRateLimit == 0)
{
Expand All @@ -1873,6 +1865,12 @@ void CCore::SetClientScriptFrameRateLimit(uint uiClientScriptFrameRateLimit)
RecalculateFrameRateLimit(-1, false);
}

void CCore::SetCurrentRefreshRate(uint value)
{
m_CurrentRefreshRate = value;
RecalculateFrameRateLimit(-1, false);
}

//
// Make sure the frame rate limit has been applied since the last call
//
Expand Down Expand Up @@ -1933,7 +1931,7 @@ void CCore::ApplyQueuedFrameRateLimit()
double dSpare = dTargetTimeToUse - m_FrameRateTimer.Get();
if (dSpare <= 0.0)
break;
if (dSpare >= 2.0)
if (dSpare >= 10.0)
Sleep(1);
}
m_FrameRateTimer.Reset();
Expand Down Expand Up @@ -2195,8 +2193,9 @@ void CCore::HandleIdlePulse()
DoPreFramePulse();
DoPostFramePulse();
}
if (m_pModManager->GetCurrentMod())
m_pModManager->GetCurrentMod()->IdleHandler();

if (m_pModManager->IsLoaded())
m_pModManager->GetClient()->IdleHandler();
}

//
Expand Down
16 changes: 10 additions & 6 deletions Client/core/CCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
void ApplyQueuedFrameRateLimit();
void EnsureFrameRateLimitApplied();
void SetClientScriptFrameRateLimit(uint uiClientScriptFrameRateLimit);
void SetCurrentRefreshRate(uint value);
void DoReliablePulse();

bool IsTimingCheckpoints();
Expand All @@ -238,8 +239,8 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
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; };
void RequestNewNickOnStart() { m_requestNewNickname = true; }
bool WillRequestNewNickOnStart() { return m_requestNewNickname; }
bool WasLaunchedWithConnectURI();
void HandleCrashDumpEncryption();

Expand Down Expand Up @@ -279,7 +280,9 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
void SetFakeLagCommandEnabled(bool bEnabled) { m_bFakeLagCommandEnabled = bEnabled; }
bool IsFakeLagCommandEnabled() { return m_bFakeLagCommandEnabled; }
SString GetBlueCopyrightString();
bool IsFirstFrame() const noexcept { return m_bFirstFrame; }

bool IsNetworkReady() const noexcept { return m_isNetworkReady; }
bool CanHandleKeyMessages() const noexcept { return m_menuFrame > 1; }

void SetCustomStreamingMemory(size_t szMB);
bool IsUsingCustomStreamingMemorySize();
Expand Down Expand Up @@ -346,7 +349,8 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
CKeyBinds* m_pKeyBinds;
CMouseControl* m_pMouseControl;

bool m_bFirstFrame;
unsigned short m_menuFrame{};
bool m_isNetworkReady{};
bool m_bIsOfflineMod;
bool m_bCursorToggleControls;
pfnProcessMessage m_pfnMessageProcessor;
Expand All @@ -368,8 +372,8 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
CElapsedTimeHD m_FrameRateTimer;
uint m_uiQueuedFrameRate;
bool m_bQueuedFrameRateValid;
bool m_bWaitToSetNick;
uint m_uiNewNickWaitFrames;
uint m_CurrentRefreshRate;
bool m_requestNewNickname{false};
EDiagnosticDebugType m_DiagnosticDebug;

// Below 2 are used for the UI only
Expand Down
4 changes: 2 additions & 2 deletions Client/core/CCrashDumpWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ long WINAPI CCrashDumpWriter::HandleExceptionGlobal(_EXCEPTION_POINTERS* pExcept
if (pModManager)
{
// Got a client?
if (pModManager->GetCurrentMod())
if (pModManager->IsLoaded())
{
// Protect us from "double-faults"
try
{
// Let the client handle it. If it could, continue the execution
if (pModManager->GetCurrentMod()->HandleException(pExceptionInformation))
if (pModManager->GetClient()->HandleException(pExceptionInformation))
{
// Delete the exception record and continue to search the exception stack
delete pExceptionInformation;
Expand Down
Loading

0 comments on commit 1384b37

Please sign in to comment.