From 122cd89aa90439982a97cef179845386f0614534 Mon Sep 17 00:00:00 2001
From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com>
Date: Sat, 1 Apr 2023 01:10:16 +0200
Subject: [PATCH] Fix recursive initialization of convars/concommands

'CSourceAppSystemGroup::PreInit' could be called multiple times. Added check for its actual stage before running any initialization code. This fixes the recursive init problem.
---
 r5dev/launcher/IApplication.cpp | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/r5dev/launcher/IApplication.cpp b/r5dev/launcher/IApplication.cpp
index 4370aaea..73f8db32 100644
--- a/r5dev/launcher/IApplication.cpp
+++ b/r5dev/launcher/IApplication.cpp
@@ -38,11 +38,15 @@
 //-----------------------------------------------------------------------------
 bool CSourceAppSystemGroup::PreInit(CSourceAppSystemGroup* pSourceAppSystemGroup)
 {
-	ConVar::InitShipped();
-	ConVar::PurgeShipped();
-	ConCommand::StaticInit();
-	ConCommand::InitShipped();
-	ConCommand::PurgeShipped();
+	if (pSourceAppSystemGroup->GetCurrentStage() == CSourceAppSystemGroup::CREATION)
+	{
+		ConVar::InitShipped();
+		ConVar::PurgeShipped();
+		ConCommand::StaticInit();
+		ConCommand::InitShipped();
+		ConCommand::PurgeShipped();
+	}
+
 	return CSourceAppSystemGroup__PreInit(pSourceAppSystemGroup);
 }