Skip to content

Commit 9662297

Browse files
Synchronize changes from 1.6 master branch [ci skip]
66290a8 Fix null-pointer access crash b1e88dd Wait for network to become ready on launch 2d4c878 Tiny update for CModManager::Load 8890b94 Refactor and improve deathmatch loading
2 parents fa3f777 + 66290a8 commit 9662297

18 files changed

+344
-435
lines changed

Client/cefweb/CWebCore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ std::unordered_set<SString> CWebCore::AllowPendingPages(bool bRemember)
409409
}
410410

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

Client/core/CChat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,11 @@ bool CChat::CharacterKeyHandler(CGUIKeyEventArgs KeyboardArgs)
699699
SString strPlayerNamePart = strCurrentInput.substr(iFound);
700700

701701
CModManager* pModManager = CModManager::GetSingletonPtr();
702-
if (pModManager && pModManager->GetCurrentMod())
702+
if (pModManager && pModManager->IsLoaded())
703703
{
704704
// Create vector and get playernames from deathmatch module
705705
std::vector<SString> vPlayerNames;
706-
pModManager->GetCurrentMod()->GetPlayerNames(vPlayerNames);
706+
pModManager->GetClient()->GetPlayerNames(vPlayerNames);
707707

708708
for (std::vector<SString>::iterator iter = vPlayerNames.begin(); iter != vPlayerNames.end(); ++iter)
709709
{

Client/core/CCommandFuncs.cpp

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -167,36 +167,13 @@ void CCommandFuncs::Clear(const char* szParameters)
167167

168168
void CCommandFuncs::Load(const char* szParameters)
169169
{
170-
if (!szParameters)
171-
{
172-
CCore::GetSingleton().GetConsole()->Printf("* Syntax: load <mod-name> [<arguments>]");
173-
return;
174-
}
175-
176-
// Copy the buffer
177-
char* szTemp = new char[strlen(szParameters) + 1];
178-
strcpy(szTemp, szParameters);
179-
180-
// Split it up into mod name and the arguments
181-
char* szModName = strtok(szTemp, " ");
182-
char* szArguments = strtok(NULL, "\0");
183-
184-
if (szModName)
185-
{
186-
// Load the mod with the given arguments
187-
CModManager::GetSingleton().RequestLoad(szModName, szArguments);
188-
}
189-
else
190-
CCore::GetSingleton().GetConsole()->Printf("* Syntax: load <mod-name> [<arguments>]");
191-
192-
// Free the temp buffer
193-
delete[] szTemp;
170+
CModManager::GetSingleton().RequestLoad(szParameters);
194171
}
195172

196173
void CCommandFuncs::Unload(const char* szParameters)
197174
{
198175
// Any mod loaded?
199-
if (CModManager::GetSingleton().GetCurrentMod())
176+
if (CModManager::GetSingleton().IsLoaded())
200177
{
201178
// Unload it
202179
CModManager::GetSingleton().RequestUnload();
@@ -209,6 +186,12 @@ void CCommandFuncs::Unload(const char* szParameters)
209186

210187
void CCommandFuncs::Connect(const char* szParameters)
211188
{
189+
if (!CCore::GetSingleton().IsNetworkReady())
190+
{
191+
CCore::GetSingleton().GetConsole()->Print(_("connect: Network is not ready, please wait a moment"));
192+
return;
193+
}
194+
212195
// Parse the arguments (host port nick pass)
213196
char szBuffer[256] = "";
214197
if (szParameters)
@@ -264,7 +247,7 @@ void CCommandFuncs::Connect(const char* szParameters)
264247
CModManager::GetSingleton().Unload();
265248

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

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

297280
void CCommandFuncs::Reconnect(const char* szParameters)
298281
{
282+
if (!CCore::GetSingleton().IsNetworkReady())
283+
{
284+
CCore::GetSingleton().GetConsole()->Print(_("reconnect: Network is not ready, please wait a moment"));
285+
return;
286+
}
287+
299288
CModManager::GetSingleton().Unload();
300289

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

311300
// Any mod loaded?
312-
if (!CModManager::GetSingleton().GetCurrentMod())
301+
if (!CModManager::GetSingleton().IsLoaded())
313302
{
314303
// Verify and convert the port number
315304
if (uiPort <= 0 || uiPort > 0xFFFF)

Client/core/CConnectManager.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ bool CConnectManager::Connect(const char* szHost, unsigned short usPort, const c
5252
assert(szNick);
5353
assert(szPassword);
5454

55+
if (!CCore::GetSingleton().IsNetworkReady())
56+
{
57+
CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->ShowNetworkNotReadyWindow();
58+
return false;
59+
}
60+
5561
m_bNotifyServerBrowser = bNotifyServerBrowser;
5662

5763
// For detecting startup problems
@@ -337,10 +343,13 @@ void CConnectManager::DoPulse()
337343
}
338344
else if (m_bReconnect)
339345
{
340-
std::string strNick;
341-
CVARS_GET("nick", strNick);
342-
Connect(m_strHost.c_str(), m_usPort, strNick.c_str(), m_strPassword.c_str(), false);
343-
m_bReconnect = false;
346+
if (CCore::GetSingleton().IsNetworkReady())
347+
{
348+
std::string strNick;
349+
CVARS_GET("nick", strNick);
350+
Connect(m_strHost.c_str(), m_usPort, strNick.c_str(), m_strPassword.c_str(), false);
351+
m_bReconnect = false;
352+
}
344353
}
345354
}
346355

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

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

401410
// Load the mod
402-
if (!CModManager::GetSingleton().Load(strModName, strArguments))
411+
if (!CModManager::GetSingleton().Load(strArguments))
403412
{
404413
// Failed loading the mod
405414
strArguments.Format(_("No such mod installed (%s)"), strModName.c_str());

Client/core/CCore.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,11 @@ CCore::CCore()
117117
m_pfnMessageProcessor = NULL;
118118
m_pMessageBox = NULL;
119119

120-
m_bFirstFrame = true;
121120
m_bIsOfflineMod = false;
122121
m_bQuitOnPulse = false;
123122
m_bDestroyMessageBox = false;
124123
m_bCursorToggleControls = false;
125124
m_bLastFocused = true;
126-
m_bWaitToSetNick = false;
127125
m_DiagnosticDebug = EDiagnosticDebug::NONE;
128126

129127
// Create our Direct3DData handler.
@@ -151,7 +149,6 @@ CCore::CCore()
151149
m_bDoneFrameRateLimit = false;
152150
m_uiFrameRateLimit = 0;
153151
m_uiServerFrameRateLimit = 0;
154-
m_uiNewNickWaitFrames = 0;
155152
m_iUnminimizeFrameCounter = 0;
156153
m_bDidRecreateRenderTargets = false;
157154
m_fMinStreamingMemory = 0;
@@ -515,7 +512,7 @@ void CCore::EnableChatInput(char* szCommand, DWORD dwColor)
515512
{
516513
if (m_pLocalGUI)
517514
{
518-
if (m_pGame->GetSystemState() == 9 /* GS_PLAYING_GAME */ && m_pModManager->GetCurrentMod() != NULL && !IsOfflineMod() && !m_pGame->IsAtMenu() &&
515+
if (m_pGame->GetSystemState() == 9 /* GS_PLAYING_GAME */ && m_pModManager->IsLoaded() && !IsOfflineMod() && !m_pGame->IsAtMenu() &&
519516
!m_pLocalGUI->GetMainMenu()->IsVisible() && !m_pLocalGUI->GetConsole()->IsVisible() && !m_pLocalGUI->IsChatBoxInputEnabled())
520517
{
521518
CChat* pChat = m_pLocalGUI->GetChat();
@@ -1236,16 +1233,22 @@ void CCore::DoPostFramePulse()
12361233
// This is the first frame in the menu?
12371234
if (m_pGame->GetSystemState() == 7) // GS_FRONTEND
12381235
{
1239-
if (m_bFirstFrame)
1240-
{
1241-
m_bFirstFrame = false;
1236+
if (m_menuFrame < 255)
1237+
++m_menuFrame;
12421238

1239+
if (m_menuFrame == 1)
1240+
{
12431241
WatchDogCompletedSection("L2"); // gta_sa.set seems ok
12441242
WatchDogCompletedSection("L3"); // No hang on startup
12451243
HandleCrashDumpEncryption();
12461244

12471245
// Disable vsync while it's all dark
12481246
m_pGame->DisableVSync();
1247+
}
1248+
1249+
if (m_menuFrame >= 5 && !m_isNetworkReady && m_pNet->IsReady())
1250+
{
1251+
m_isNetworkReady = true;
12491252

12501253
// Parse the command line
12511254
// Does it begin with mtasa://?
@@ -1262,33 +1265,18 @@ void CCore::DoPostFramePulse()
12621265
{
12631266
// We want to load a mod?
12641267
const char* szOptionValue;
1265-
if (szOptionValue = GetCommandLineOption("l"))
1266-
{
1267-
// Try to load the mod
1268-
if (!m_pModManager->Load(szOptionValue, m_szCommandLineArgs))
1269-
{
1270-
SString strTemp(_("Error running mod specified in command line ('%s')"), szOptionValue);
1271-
ShowMessageBox(_("Error") + _E("CC42"), strTemp, MB_BUTTON_OK | MB_ICON_ERROR); // Command line Mod load failed
1272-
}
1273-
}
1274-
// We want to connect to a server?
1275-
else if (szOptionValue = GetCommandLineOption("c"))
1268+
if (szOptionValue = GetCommandLineOption("c"))
12761269
{
12771270
CCommandFuncs::Connect(szOptionValue);
12781271
}
12791272
}
12801273
}
12811274

1282-
if (m_bWaitToSetNick && GetLocalGUI()->GetMainMenu()->IsVisible() && !GetLocalGUI()->GetMainMenu()->IsFading())
1275+
if (m_menuFrame >= 75 && m_requestNewNickname && GetLocalGUI()->GetMainMenu()->IsVisible() && !GetLocalGUI()->GetMainMenu()->IsFading())
12831276
{
1284-
if (m_uiNewNickWaitFrames > 75)
1285-
{
1286-
// Request a new nickname if we're waiting for one
1287-
GetLocalGUI()->GetMainMenu()->GetSettingsWindow()->RequestNewNickname();
1288-
m_bWaitToSetNick = false;
1289-
}
1290-
else
1291-
m_uiNewNickWaitFrames++;
1277+
// Request a new nickname if we're waiting for one
1278+
GetLocalGUI()->GetMainMenu()->GetSettingsWindow()->RequestNewNickname();
1279+
m_requestNewNickname = false;
12921280
}
12931281
}
12941282

@@ -2195,8 +2183,9 @@ void CCore::HandleIdlePulse()
21952183
DoPreFramePulse();
21962184
DoPostFramePulse();
21972185
}
2198-
if (m_pModManager->GetCurrentMod())
2199-
m_pModManager->GetCurrentMod()->IdleHandler();
2186+
2187+
if (m_pModManager->IsLoaded())
2188+
m_pModManager->GetClient()->IdleHandler();
22002189
}
22012190

22022191
//

Client/core/CCore.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
238238
std::map<std::string, std::string>& GetCommandLineOptions() { return m_CommandLineOptions; }
239239
const char* GetCommandLineOption(const char* szOption);
240240
const char* GetCommandLineArgs() { return m_szCommandLineArgs; }
241-
void RequestNewNickOnStart() { m_bWaitToSetNick = true; };
242-
bool WillRequestNewNickOnStart() { return m_bWaitToSetNick; };
241+
void RequestNewNickOnStart() { m_requestNewNickname = true; }
242+
bool WillRequestNewNickOnStart() { return m_requestNewNickname; }
243243
bool WasLaunchedWithConnectURI();
244244
void HandleCrashDumpEncryption();
245245

@@ -279,7 +279,9 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
279279
void SetFakeLagCommandEnabled(bool bEnabled) { m_bFakeLagCommandEnabled = bEnabled; }
280280
bool IsFakeLagCommandEnabled() { return m_bFakeLagCommandEnabled; }
281281
SString GetBlueCopyrightString();
282-
bool IsFirstFrame() const noexcept { return m_bFirstFrame; }
282+
283+
bool IsNetworkReady() const noexcept { return m_isNetworkReady; }
284+
bool CanHandleKeyMessages() const noexcept { return m_menuFrame > 1; }
283285

284286
void SetCustomStreamingMemory(size_t szMB);
285287
bool IsUsingCustomStreamingMemorySize();
@@ -346,7 +348,8 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
346348
CKeyBinds* m_pKeyBinds;
347349
CMouseControl* m_pMouseControl;
348350

349-
bool m_bFirstFrame;
351+
unsigned short m_menuFrame{};
352+
bool m_isNetworkReady{};
350353
bool m_bIsOfflineMod;
351354
bool m_bCursorToggleControls;
352355
pfnProcessMessage m_pfnMessageProcessor;
@@ -368,8 +371,7 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
368371
CElapsedTimeHD m_FrameRateTimer;
369372
uint m_uiQueuedFrameRate;
370373
bool m_bQueuedFrameRateValid;
371-
bool m_bWaitToSetNick;
372-
uint m_uiNewNickWaitFrames;
374+
bool m_requestNewNickname{false};
373375
EDiagnosticDebugType m_DiagnosticDebug;
374376

375377
// Below 2 are used for the UI only

Client/core/CCrashDumpWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ long WINAPI CCrashDumpWriter::HandleExceptionGlobal(_EXCEPTION_POINTERS* pExcept
194194
if (pModManager)
195195
{
196196
// Got a client?
197-
if (pModManager->GetCurrentMod())
197+
if (pModManager->IsLoaded())
198198
{
199199
// Protect us from "double-faults"
200200
try
201201
{
202202
// Let the client handle it. If it could, continue the execution
203-
if (pModManager->GetCurrentMod()->HandleException(pExceptionInformation))
203+
if (pModManager->GetClient()->HandleException(pExceptionInformation))
204204
{
205205
// Delete the exception record and continue to search the exception stack
206206
delete pExceptionInformation;

0 commit comments

Comments
 (0)