From 5f7bf4414ec80584d40f5205c957554446210452 Mon Sep 17 00:00:00 2001
From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com>
Date: Sun, 12 Feb 2023 00:05:27 +0100
Subject: [PATCH] Add additional miles debug info

Log the amount of time it took to initialize miles. Also log the language it gets initialized with, as this has been a common problem in the past. This should make it easier to see the problem regarding audio initialization failures.
---
 r5dev/codecs/Miles/miles_impl.cpp | 18 +++++++++++++-----
 r5dev/codecs/Miles/miles_types.h  |  2 ++
 r5dev/tier1/IConVar.cpp           |  4 ++--
 r5dev/tier1/cvar.cpp              |  1 +
 r5dev/tier1/cvar.h                |  1 +
 5 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/r5dev/codecs/Miles/miles_impl.cpp b/r5dev/codecs/Miles/miles_impl.cpp
index d6ae2055..f33f147e 100644
--- a/r5dev/codecs/Miles/miles_impl.cpp
+++ b/r5dev/codecs/Miles/miles_impl.cpp
@@ -1,5 +1,6 @@
 #include "core/stdafx.h"
 #include "miles_impl.h"
+#include "tier0/fasttimer.h"
 #include "tier1/cvar.h"
 
 //-----------------------------------------------------------------------------
@@ -19,20 +20,27 @@ void AIL_LogFunc(int64_t nLogLevel, const char* pszMessage)
 //-----------------------------------------------------------------------------
 bool Miles_Initialize()
 {
-	DevMsg(eDLL_T::AUDIO, "%s: initializing Miles Sound System\n", __FUNCTION__);
+	const char* pszLanguage = miles_language->GetString();
+	if (!pszLanguage[0])
+	{
+		pszLanguage = MILES_DEFAULT_LANGUAGE;
+	}
 
+	DevMsg(eDLL_T::AUDIO, "%s: initializing MSS with language: '%s'\n", __FUNCTION__, pszLanguage);
+	CFastTimer initTimer;
+
+	initTimer.Start();
 	bool bResult = v_Miles_Initialize();
+	initTimer.End();
 
-	bResult	? DevMsg(eDLL_T::AUDIO, "%s: %s\n", __FUNCTION__, "initialized successfully")
-			: Warning(eDLL_T::AUDIO, "%s: %s\n", __FUNCTION__, "failed to initialize");
-
+	DevMsg(eDLL_T::AUDIO, "%s: %s ('%f' seconds)\n", __FUNCTION__, bResult ? "success" : "failure", initTimer.GetDuration().GetSeconds());
 	return bResult;
 }
 
 void MilesQueueEventRun(Miles::Queue* queue, const char* eventName)
 {
 	if(miles_debug->GetBool())
-		DevMsg(eDLL_T::AUDIO, "%s: running event '%s'\n", __FUNCTION__, eventName);
+		DevMsg(eDLL_T::AUDIO, "%s: running event: '%s'\n", __FUNCTION__, eventName);
 
 	v_MilesQueueEventRun(queue, eventName);
 }
diff --git a/r5dev/codecs/Miles/miles_types.h b/r5dev/codecs/Miles/miles_types.h
index 726be179..bae8703a 100644
--- a/r5dev/codecs/Miles/miles_types.h
+++ b/r5dev/codecs/Miles/miles_types.h
@@ -1,5 +1,7 @@
 #pragma once
 
+constexpr char MILES_DEFAULT_LANGUAGE[] = "english";
+
 namespace Miles
 {
 	struct Queue
diff --git a/r5dev/tier1/IConVar.cpp b/r5dev/tier1/IConVar.cpp
index e2250f68..1d2eb186 100644
--- a/r5dev/tier1/IConVar.cpp
+++ b/r5dev/tier1/IConVar.cpp
@@ -266,6 +266,7 @@ void ConVar::InitShipped(void)
 	model_defaultFadeDistScale       = g_pCVar->FindVar("model_defaultFadeDistScale");
 	model_defaultFadeDistMin         = g_pCVar->FindVar("model_defaultFadeDistMin");
 #ifndef DEDICATED
+	miles_language                   = g_pCVar->FindVar("miles_language");
 	rui_defaultDebugFontFace         = g_pCVar->FindVar("rui_defaultDebugFontFace");
 	r_visualizetraces                = g_pCVar->FindVar("r_visualizetraces");
 	r_visualizetraces_duration       = g_pCVar->FindVar("r_visualizetraces_duration");
@@ -288,12 +289,11 @@ void ConVar::InitShipped(void)
 	net_usesocketsforloopback        = g_pCVar->FindVar("net_usesocketsforloopback");
 #ifndef CLIENT_DLL
 	sv_showhitboxes = g_pCVar->FindVar("sv_showhitboxes");
+	sv_forceChatToTeamOnly = g_pCVar->FindVar("sv_forceChatToTeamOnly");
 
 	sv_showhitboxes->SetMin(-1); // Allow user to go over each entity manually without going out of bounds.
 	sv_showhitboxes->SetMax(NUM_ENT_ENTRIES - 1);
 
-	sv_forceChatToTeamOnly = g_pCVar->FindVar("sv_forceChatToTeamOnly");
-
 	sv_forceChatToTeamOnly->RemoveFlags(FCVAR_DEVELOPMENTONLY);
 	sv_forceChatToTeamOnly->AddFlags(FCVAR_REPLICATED);
 
diff --git a/r5dev/tier1/cvar.cpp b/r5dev/tier1/cvar.cpp
index 58efe16e..454af2fd 100644
--- a/r5dev/tier1/cvar.cpp
+++ b/r5dev/tier1/cvar.cpp
@@ -214,6 +214,7 @@ ConVar* rui_defaultDebugFontFace           = nullptr;
 // MILES                                                                      |
 #ifndef DEDICATED
 ConVar* miles_debug                        = nullptr;
+ConVar* miles_language                     = nullptr;
 #endif
 
 
diff --git a/r5dev/tier1/cvar.h b/r5dev/tier1/cvar.h
index 71d6dc40..581650ca 100644
--- a/r5dev/tier1/cvar.h
+++ b/r5dev/tier1/cvar.h
@@ -210,6 +210,7 @@ extern ConVar* rui_defaultDebugFontFace;
 // MILES                                                                      |
 #ifndef DEDICATED
 extern ConVar* miles_debug;
+extern ConVar* miles_language;
 #endif
 
 //-----------------------------------------------------------------------------