mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Force consistency within code
* Use C-style format specifiers everywhere. * Use std::string as much as possible. * Reorder CSurface class structure by groups. * Light optimizations in 'CSurface::ForwardCommandToGame'.
This commit is contained in:
parent
338d0ad3f9
commit
b169a78542
@ -651,7 +651,7 @@ void CSurface::VirtualItemToClipboard(const std::unique_ptr<MouseEventArgs>& pEv
|
||||
|
||||
string svClipBoard;
|
||||
for (uint32_t i = 0; i < lSelected.Count(); i++)
|
||||
svClipBoard.append(pSurface->m_LogList[lSelected[i]].m_svText.ToCString());
|
||||
svClipBoard.append(pSurface->m_LogList[lSelected[i]].m_svText);
|
||||
|
||||
clip::set_text(svClipBoard);
|
||||
}
|
||||
@ -719,9 +719,7 @@ void CSurface::ForwardCommandToGame(Forms::Control* pSender)
|
||||
if (vecHandles.empty())
|
||||
return;
|
||||
|
||||
const String kzCommand = pSurface->m_ConsoleCommandTextBox->Text();
|
||||
const char* szCommand = kzCommand.ToCString();
|
||||
|
||||
const string kzCommand = pSurface->m_ConsoleCommandTextBox->Text().ToCString();
|
||||
bool bSuccess = false;
|
||||
|
||||
for (const HWND hWindow : vecHandles)
|
||||
@ -729,7 +727,7 @@ void CSurface::ForwardCommandToGame(Forms::Control* pSender)
|
||||
char szWindowName[256];
|
||||
GetWindowTextA(hWindow, szWindowName, 256);
|
||||
|
||||
COPYDATASTRUCT cData = { 0, (DWORD)strnlen_s(szCommand, 259) + 1, (void*)szCommand };
|
||||
COPYDATASTRUCT cData = { 0, (DWORD)(std::min)(kzCommand.size(), (size_t)259) + 1, (void*)kzCommand.c_str() };
|
||||
bool bProcessingMessage = SendMessageA(hWindow, WM_COPYDATA, NULL, (LPARAM)&cData); // WM_COPYDATA will only return 0 or 1, that's why we use a boolean.
|
||||
if (bProcessingMessage && !bSuccess)
|
||||
{
|
||||
|
@ -3,24 +3,25 @@
|
||||
|
||||
struct LogList_t
|
||||
{
|
||||
LogList_t(const spdlog::level::level_enum nLevel, const String& svText)
|
||||
LogList_t(const spdlog::level::level_enum nLevel, const string& svText)
|
||||
{
|
||||
m_nLevel = nLevel;
|
||||
m_svText = svText;
|
||||
}
|
||||
|
||||
spdlog::level::level_enum m_nLevel;
|
||||
String m_svText;
|
||||
string m_svText;
|
||||
};
|
||||
|
||||
class CSurface : public Forms::Form
|
||||
{
|
||||
public:
|
||||
CSurface();
|
||||
virtual ~CSurface() = default;
|
||||
|
||||
virtual ~CSurface()
|
||||
{
|
||||
};
|
||||
UIX::UIXListView* ConsoleListView() const { return m_ConsoleListView; };
|
||||
std::vector<LogList_t> m_LogList;
|
||||
UIX::UIXListView* m_ConsoleListView;
|
||||
|
||||
private:
|
||||
void Init();
|
||||
@ -58,58 +59,61 @@ private:
|
||||
HIDDEN,
|
||||
};
|
||||
|
||||
UIX::UIXTextBox* m_WidthTextBox;
|
||||
UIX::UIXTextBox* m_HeightTextBox;
|
||||
UIX::UIXTextBox* m_WorkerThreadsTextBox;
|
||||
UIX::UIXTextBox* m_ReservedCoresTextBox;
|
||||
UIX::UIXTextBox* m_FpsTextBox;
|
||||
UIX::UIXTextBox* m_PlaylistFileTextBox;
|
||||
UIX::UIXTextBox* m_HostNameTextBox;
|
||||
UIX::UIXTextBox* m_LaunchArgsTextBox;
|
||||
UIX::UIXTextBox* m_ConsoleCommandTextBox;
|
||||
// Labels
|
||||
UIX::UIXLabel* m_WorkerThreadsLabel;
|
||||
UIX::UIXLabel* m_ReservedCoresLabel;
|
||||
UIX::UIXLabel* m_MapLabel;
|
||||
UIX::UIXLabel* m_PlaylistLabel;
|
||||
UIX::UIXLabel* m_ModeLabel;
|
||||
UIX::UIXLabel* m_FpsLabel;
|
||||
UIX::UIXLabel* m_ResolutionLabel;
|
||||
UIX::UIXLabel* m_PlaylistFileLabel;
|
||||
UIX::UIXLabel* m_HostNameLabel;
|
||||
UIX::UIXLabel* m_VisibilityLabel;
|
||||
UIX::UIXLabel* m_LaunchArgsLabel;
|
||||
// Boxes
|
||||
// Game.
|
||||
UIX::UIXGroupBox* m_GameGroup;
|
||||
UIX::UIXGroupBox* m_MainGroup;
|
||||
UIX::UIXGroupBox* m_GameGroupExt;
|
||||
UIX::UIXGroupBox* m_MainGroupExt;
|
||||
UIX::UIXGroupBox* m_ConsoleGroupExt;
|
||||
UIX::UIXGroupBox* m_ConsoleGroup;
|
||||
UIX::UIXGroupBox* m_EngineBaseGroup;
|
||||
UIX::UIXGroupBox* m_EngineNetworkGroup;
|
||||
UIX::UIXGroupBox* m_EngineVideoGroup;
|
||||
// Toggles
|
||||
UIX::UIXLabel* m_MapLabel;
|
||||
UIX::UIXComboBox* m_MapCombo;
|
||||
UIX::UIXLabel* m_PlaylistLabel;
|
||||
UIX::UIXComboBox* m_PlaylistCombo;
|
||||
UIX::UIXCheckBox* m_CheatsToggle;
|
||||
UIX::UIXCheckBox* m_DeveloperToggle;
|
||||
UIX::UIXCheckBox* m_ConsoleToggle;
|
||||
UIX::UIXCheckBox* m_WindowedToggle;
|
||||
UIX::UIXCheckBox* m_NoBorderToggle;
|
||||
UIX::UIXCheckBox* m_ColorConsoleToggle;
|
||||
UIX::UIXTextBox* m_PlaylistFileTextBox;
|
||||
UIX::UIXLabel* m_PlaylistFileLabel;
|
||||
|
||||
// Main.
|
||||
UIX::UIXGroupBox* m_MainGroup;
|
||||
UIX::UIXGroupBox* m_MainGroupExt;
|
||||
UIX::UIXComboBox* m_ModeCombo;
|
||||
UIX::UIXLabel* m_ModeLabel;
|
||||
UIX::UIXTextBox* m_HostNameTextBox;
|
||||
UIX::UIXLabel* m_HostNameLabel;
|
||||
UIX::UIXComboBox* m_VisibilityCombo;
|
||||
UIX::UIXLabel* m_VisibilityLabel;
|
||||
UIX::UIXTextBox* m_LaunchArgsTextBox;
|
||||
UIX::UIXLabel* m_LaunchArgsLabel;
|
||||
UIX::UIXButton* m_CleanSDK;
|
||||
UIX::UIXButton* m_UpdateSDK;
|
||||
UIX::UIXButton* m_LaunchSDK;
|
||||
|
||||
// Engine.
|
||||
UIX::UIXGroupBox* m_EngineBaseGroup;
|
||||
UIX::UIXGroupBox* m_EngineNetworkGroup;
|
||||
UIX::UIXGroupBox* m_EngineVideoGroup;
|
||||
UIX::UIXTextBox* m_ReservedCoresTextBox;
|
||||
UIX::UIXLabel* m_ReservedCoresLabel;
|
||||
UIX::UIXTextBox* m_WorkerThreadsTextBox;
|
||||
UIX::UIXLabel* m_WorkerThreadsLabel;
|
||||
UIX::UIXCheckBox* m_SingleCoreDediToggle;
|
||||
UIX::UIXCheckBox* m_NoAsyncJobsToggle;
|
||||
UIX::UIXCheckBox* m_NetEncryptionToggle;
|
||||
UIX::UIXCheckBox* m_NetRandomKeyToggle;
|
||||
UIX::UIXCheckBox* m_NoQueuedPacketThread;
|
||||
UIX::UIXCheckBox* m_NoTimeOutToggle;
|
||||
UIX::UIXCheckBox* m_ColorConsoleToggle;
|
||||
// Combo
|
||||
UIX::UIXComboBox* m_MapCombo;
|
||||
UIX::UIXComboBox* m_PlaylistCombo;
|
||||
UIX::UIXComboBox* m_ModeCombo;
|
||||
UIX::UIXComboBox* m_VisibilityCombo;
|
||||
// Buttons
|
||||
UIX::UIXButton* m_CleanSDK;
|
||||
UIX::UIXButton* m_UpdateSDK;
|
||||
UIX::UIXButton* m_LaunchSDK;
|
||||
UIX::UIXCheckBox* m_WindowedToggle;
|
||||
UIX::UIXCheckBox* m_NoBorderToggle;
|
||||
UIX::UIXTextBox* m_FpsTextBox;
|
||||
UIX::UIXLabel* m_FpsLabel;
|
||||
UIX::UIXTextBox* m_WidthTextBox;
|
||||
UIX::UIXTextBox* m_HeightTextBox;
|
||||
UIX::UIXLabel* m_ResolutionLabel;
|
||||
|
||||
// Console.
|
||||
UIX::UIXGroupBox* m_ConsoleGroup;
|
||||
UIX::UIXGroupBox* m_ConsoleGroupExt;
|
||||
UIX::UIXListView* m_ConsoleListView;
|
||||
UIX::UIXTextBox* m_ConsoleCommandTextBox;
|
||||
UIX::UIXButton* m_ConsoleSendCommand;
|
||||
};
|
||||
|
@ -46,14 +46,14 @@ void CLauncher::InitLogger()
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Purpose: handles user input pre-init
|
||||
// Input : argc -
|
||||
// *argv -
|
||||
// *argv[] -
|
||||
// Output : exit_code (-1 if EntryPoint should continue to HandleInput)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
int CLauncher::HandleCommandLine(int argc, char* argv[])
|
||||
{
|
||||
for (int i = 1; i < __argc; ++i)
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
string arg = __argv[i];
|
||||
string arg = argv[i];
|
||||
eLaunchMode mode = eLaunchMode::LM_NONE;
|
||||
|
||||
if ((arg == "-developer") || (arg == "-dev"))
|
||||
@ -100,11 +100,11 @@ int CLauncher::HandleCommandLine(int argc, char* argv[])
|
||||
int CLauncher::HandleInput()
|
||||
{
|
||||
std::cout << "----------------------------------------------------------------------------------------------------------------------" << std::endl;
|
||||
AddLog(spdlog::level::level_enum::warn, "The '{:s}' options are for development purposes; use the '{:s}' options for default usage.\n", "DEV", "PROD");
|
||||
AddLog(spdlog::level::level_enum::warn, "The '%s' options are for development purposes; use the '%s' options for default usage.\n", "DEV", "PROD");
|
||||
std::cout << "----------------------------------------------------------------------------------------------------------------------" << std::endl;
|
||||
AddLog(spdlog::level::level_enum::info, "{:6s} ('0' = {:s} | '1' = {:s}).\n", "GAME", "DEV", "PROD");
|
||||
AddLog(spdlog::level::level_enum::info, "{:6s} ('2' = {:s} | '3' = {:s}).\n", "SERVER", "DEV", "PROD");
|
||||
AddLog(spdlog::level::level_enum::info, "{:6s} ('4' = {:s} | '5' = {:s}).\n", "CLIENT", "DEV", "PROD");
|
||||
AddLog(spdlog::level::level_enum::info, "%-6s ('0' = %s | '1' = %s).\n", "GAME", "DEV", "PROD");
|
||||
AddLog(spdlog::level::level_enum::info, "%-6s ('2' = %s | '3' = %s).\n", "SERVER", "DEV", "PROD");
|
||||
AddLog(spdlog::level::level_enum::info, "%-6s ('4' = %s | '5' = %s).\n", "CLIENT", "DEV", "PROD");
|
||||
std::cout << "----------------------------------------------------------------------------------------------------------------------" << std::endl;
|
||||
std::cout << "User input: ";
|
||||
|
||||
@ -127,7 +127,7 @@ int CLauncher::HandleInput()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
AddLog(spdlog::level::level_enum::err, "SDK Launcher only takes numerical input (error = {:s}).\n", e.what());
|
||||
AddLog(spdlog::level::level_enum::err, "SDK Launcher only takes numerical input (error = %s).\n", e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@ -152,7 +152,7 @@ bool CLauncher::CreateLaunchContext(eLaunchMode lMode, const char* szCommandLine
|
||||
if (!szConfig) { szConfig = "startup_dev.cfg"; }
|
||||
|
||||
SetupLaunchContext(szConfig, MAIN_WORKER_DLL, MAIN_GAME_DLL, szCommandLine);
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING GAME [{:s}] ***\n", "DEV");
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING GAME [%s] ***\n", "DEV");
|
||||
break;
|
||||
}
|
||||
case eLaunchMode::LM_GAME:
|
||||
@ -160,7 +160,7 @@ bool CLauncher::CreateLaunchContext(eLaunchMode lMode, const char* szCommandLine
|
||||
if (!szConfig) { szConfig = "startup_retail.cfg"; }
|
||||
|
||||
SetupLaunchContext(szConfig, MAIN_WORKER_DLL, MAIN_GAME_DLL, szCommandLine);
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING GAME [{:s}] ***\n", "PROD");
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING GAME [%s] ***\n", "PROD");
|
||||
break;
|
||||
}
|
||||
case eLaunchMode::LM_SERVER_DEV:
|
||||
@ -168,7 +168,7 @@ bool CLauncher::CreateLaunchContext(eLaunchMode lMode, const char* szCommandLine
|
||||
if (!szConfig) { szConfig = "startup_dedi_dev.cfg"; }
|
||||
|
||||
SetupLaunchContext(szConfig, SERVER_WORKER_DLL, SERVER_GAME_DLL, szCommandLine);
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING SERVER [{:s}] ***\n", "DEV");
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING SERVER [%s] ***\n", "DEV");
|
||||
break;
|
||||
}
|
||||
case eLaunchMode::LM_SERVER:
|
||||
@ -176,7 +176,7 @@ bool CLauncher::CreateLaunchContext(eLaunchMode lMode, const char* szCommandLine
|
||||
if (!szConfig) { szConfig = "startup_dedi_retail.cfg"; }
|
||||
|
||||
SetupLaunchContext(szConfig, SERVER_WORKER_DLL, SERVER_GAME_DLL, szCommandLine);
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING SERVER [{:s}] ***\n", "PROD");
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING SERVER [%s] ***\n", "PROD");
|
||||
break;
|
||||
}
|
||||
case eLaunchMode::LM_CLIENT_DEV:
|
||||
@ -184,7 +184,7 @@ bool CLauncher::CreateLaunchContext(eLaunchMode lMode, const char* szCommandLine
|
||||
if (!szConfig) { szConfig = "startup_client_dev.cfg"; }
|
||||
|
||||
SetupLaunchContext(szConfig, CLIENT_WORKER_DLL, MAIN_GAME_DLL, szCommandLine);
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING CLIENT [{:s}] ***\n", "DEV");
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING CLIENT [%s] ***\n", "DEV");
|
||||
break;
|
||||
}
|
||||
case eLaunchMode::LM_CLIENT:
|
||||
@ -192,7 +192,7 @@ bool CLauncher::CreateLaunchContext(eLaunchMode lMode, const char* szCommandLine
|
||||
if (!szConfig) { szConfig = "startup_client_retail.cfg"; }
|
||||
|
||||
SetupLaunchContext(szConfig, CLIENT_WORKER_DLL, MAIN_GAME_DLL, szCommandLine);
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING CLIENT [{:s}] ***\n", "PROD");
|
||||
AddLog(spdlog::level::level_enum::info, "*** LAUNCHING CLIENT [%s] ***\n", "PROD");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -223,12 +223,12 @@ void CLauncher::SetupLaunchContext(const char* szConfig, const char* szWorkerDll
|
||||
{
|
||||
if (!cfgFile.ReadString(commandLine))
|
||||
{
|
||||
AddLog(spdlog::level::level_enum::err, Format("Failed to read file '%s'!\n", szConfig));
|
||||
AddLog(spdlog::level::level_enum::err, "Failed to read file '%s'!\n", szConfig);
|
||||
}
|
||||
}
|
||||
else // Failed to open config file.
|
||||
{
|
||||
AddLog(spdlog::level::level_enum::err, Format("Failed to open file '%s'!\n", szConfig));
|
||||
AddLog(spdlog::level::level_enum::err, "Failed to open file '%s'!\n", szConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,10 +244,10 @@ void CLauncher::SetupLaunchContext(const char* szConfig, const char* szWorkerDll
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Print the file paths and arguments.
|
||||
std::cout << "----------------------------------------------------------------------------------------------------------------------" << std::endl;
|
||||
AddLog(spdlog::level::level_enum::debug, "- CWD: {:s}\n", m_svCurrentDir);
|
||||
AddLog(spdlog::level::level_enum::debug, "- EXE: {:s}\n", m_svGameExe);
|
||||
AddLog(spdlog::level::level_enum::debug, "- DLL: {:s}\n", m_svWorkerDll);
|
||||
AddLog(spdlog::level::level_enum::debug, "- CLI: {:s}\n", commandLine);
|
||||
AddLog(spdlog::level::level_enum::debug, "- CWD: %s\n", m_svCurrentDir.c_str());
|
||||
AddLog(spdlog::level::level_enum::debug, "- EXE: %s\n", m_svGameExe.c_str());
|
||||
AddLog(spdlog::level::level_enum::debug, "- DLL: %s\n", m_svWorkerDll.c_str());
|
||||
AddLog(spdlog::level::level_enum::debug, "- CLI: %s\n", commandLine.c_str());
|
||||
std::cout << "----------------------------------------------------------------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
|
||||
@ -342,7 +342,7 @@ BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
|
||||
int main(int argc, char* argv[], char* envp[])
|
||||
{
|
||||
g_pLauncher->InitLogger();
|
||||
if (__argc < 2)
|
||||
if (argc < 2)
|
||||
{
|
||||
#ifdef NDEBUG
|
||||
FreeConsole();
|
||||
@ -351,7 +351,7 @@ int main(int argc, char* argv[], char* envp[])
|
||||
}
|
||||
else
|
||||
{
|
||||
int results = g_pLauncher->HandleCommandLine(__argc, __argv);
|
||||
int results = g_pLauncher->HandleCommandLine(argc, argv);
|
||||
if (results != -1)
|
||||
return results;
|
||||
|
||||
|
@ -18,18 +18,23 @@ public:
|
||||
delete m_pSurface;
|
||||
}
|
||||
}
|
||||
template <typename T, typename ...P>
|
||||
void AddLog(spdlog::level::level_enum nLevel, T&& svFormat, P &&... vParams)
|
||||
|
||||
void AddLog(spdlog::level::level_enum nLevel, const char* szFormat, ...)
|
||||
{
|
||||
String svBuffer = fmt::format(std::forward<T>(svFormat), std::forward<P>(vParams)...).c_str();
|
||||
m_pLogger->log(nLevel, svBuffer.ToCString());
|
||||
string svBuffer;
|
||||
va_list args;
|
||||
va_start(args, szFormat);
|
||||
svBuffer = FormatV(szFormat, args);
|
||||
va_end(args);
|
||||
|
||||
m_pLogger->log(nLevel, svBuffer);
|
||||
m_pLogger->flush();
|
||||
|
||||
if (m_pSurface)
|
||||
{
|
||||
m_pSurface->m_LogList.push_back(LogList_t(nLevel, svBuffer));
|
||||
m_pSurface->m_ConsoleListView->SetVirtualListSize(static_cast<int32_t>(m_pSurface->m_LogList.size()));
|
||||
m_pSurface->m_ConsoleListView->Refresh();
|
||||
m_pSurface->ConsoleListView()->SetVirtualListSize(static_cast<int32_t>(m_pSurface->m_LogList.size()));
|
||||
m_pSurface->ConsoleListView()->Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user