From ee3e2b8f2aa6a439c210a98ca600dfb8a1f13376 Mon Sep 17 00:00:00 2001
From: Amos <k.mazidjatari@gmail.com>
Date: Tue, 22 Aug 2023 19:32:21 +0200
Subject: [PATCH] Use CUtlString

---
 r5dev/engine/sys_dll.cpp            |  4 ++--
 r5dev/pluginsystem/pluginsystem.cpp | 15 ++++++++-------
 r5dev/pluginsystem/pluginsystem.h   | 14 ++++++++++----
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/r5dev/engine/sys_dll.cpp b/r5dev/engine/sys_dll.cpp
index dac12f72..dbea2b05 100644
--- a/r5dev/engine/sys_dll.cpp
+++ b/r5dev/engine/sys_dll.cpp
@@ -149,9 +149,9 @@ void CModAppSystemGroup::InitPluginSystem(CModAppSystemGroup* pModAppSystemGroup
 	for (auto& it : g_pPluginSystem->GetPluginInstances())
 	{
 		if (g_pPluginSystem->LoadPluginInstance(it))
-			Msg(eDLL_T::ENGINE, "Loaded plugin: '%s'\n", it.m_svPluginName.c_str());
+			Msg(eDLL_T::ENGINE, "Loaded plugin: '%s'\n", it.m_Name.String());
 		else
-			Warning(eDLL_T::ENGINE, "Failed loading plugin: '%s'\n", it.m_svPluginName.c_str());
+			Warning(eDLL_T::ENGINE, "Failed loading plugin: '%s'\n", it.m_Name.String());
 	}
 }
 
diff --git a/r5dev/pluginsystem/pluginsystem.cpp b/r5dev/pluginsystem/pluginsystem.cpp
index fc886167..5d84463d 100644
--- a/r5dev/pluginsystem/pluginsystem.cpp
+++ b/r5dev/pluginsystem/pluginsystem.cpp
@@ -29,14 +29,15 @@ void CPluginSystem::PluginSystem_Init()
 		bool addInstance = true;
 		for (auto& inst : pluginInstances)
 		{
-			if (inst.m_svPluginFullPath.compare(path.Get()) == 0)
+			if (inst.m_Path.IsEqual_CaseInsensitive(path.String()) == 0)
 				addInstance = false;
 		}
 
-		const char* baseFileName = V_UnqualifiedFileName(path.Get());
-
 		if (addInstance)
-			pluginInstances.push_back(PluginInstance_t(baseFileName, path.Get()));
+		{
+			const char* baseFileName = V_UnqualifiedFileName(path.String());
+			pluginInstances.push_back(PluginInstance_t(baseFileName, path.String()));
+		}
 	}
 }
 
@@ -50,11 +51,11 @@ bool CPluginSystem::LoadPluginInstance(PluginInstance_t& pluginInst)
 	if (pluginInst.m_bIsLoaded)
 		return false;
 
-	HMODULE loadedPlugin = LoadLibraryA(pluginInst.m_svPluginFullPath.c_str());
+	HMODULE loadedPlugin = LoadLibraryA(pluginInst.m_Path.String());
 	if (loadedPlugin == INVALID_HANDLE_VALUE || loadedPlugin == 0)
 		return false;
 
-	CModule pluginModule(pluginInst.m_svPluginName.c_str());
+	CModule pluginModule(pluginInst.m_Name.String());
 
 	// Pass selfModule here on load function, we have to do
 	// this because local listen/dedi/client dll's are called
@@ -64,7 +65,7 @@ bool CPluginSystem::LoadPluginInstance(PluginInstance_t& pluginInst)
 
 	Assert(onLoadFn);
 
-	if (!onLoadFn(pluginInst.m_svPluginName.c_str(), g_SDKDll.GetModuleName().c_str()))
+	if (!onLoadFn(pluginInst.m_Name.String(), g_SDKDll.GetModuleName().c_str()))
 	{
 		FreeLibrary(loadedPlugin);
 		return false;
diff --git a/r5dev/pluginsystem/pluginsystem.h b/r5dev/pluginsystem/pluginsystem.h
index da8dda72..74ee1973 100644
--- a/r5dev/pluginsystem/pluginsystem.h
+++ b/r5dev/pluginsystem/pluginsystem.h
@@ -80,16 +80,22 @@ class CPluginSystem : IPluginSystem
 public:	
 	struct PluginInstance_t
 	{
-		PluginInstance_t(string svPluginName, string svPluginFullPath) : m_svPluginName(svPluginName), m_svPluginFullPath(svPluginFullPath), m_svDescription(std::string()), m_bIsLoaded(false) {};
+		PluginInstance_t(const char* pName, const char* pPath, const char* pDescription = "")
+			: m_Name(pName)
+			, m_Path(pPath)
+			, m_Description(pDescription)
+			, m_bIsLoaded(false)
+		{
+		};
 
 		// Might wanna make a status code system.
 		typedef bool(*OnLoad)(const char*, const char*);
 		typedef void(*OnUnload)();
 
 		CModule m_hModule;
-		string m_svPluginName;
-		string m_svPluginFullPath;
-		string m_svDescription;
+		CUtlString m_Name;
+		CUtlString m_Path;
+		CUtlString m_Description;
 		bool m_bIsLoaded; // [ PIXIE ]: I don't like this and it's bad.
 		// I will make a module manager later which will grab all modules from the process and adds each module / removes module that passes through DLLMain.
 	};