Update launcher

Adds spdlog library instead for clearer output.
Adds precompiled header for slightly faster compilation.
Updated print text with clearer details.
Renamed to "r5reloaded.exe" instead to match files in game directory
This commit is contained in:
Amos 2021-09-12 07:15:42 -07:00
parent 2da6d71fb3
commit fad7906fd8
8 changed files with 114 additions and 85 deletions

View File

@ -1,15 +1,8 @@
#include <string>
#include <stdio.h>
#include <iostream>
#include <Windows.h>
#include <detours.h>
#include <filesystem>
#include <fstream>
#include <sstream>
#include "pch.h"
#include "main.h"
//----------------------------------------------------------------------------
// Print the error message to the console if any
// Print the error message to the console if any.
//----------------------------------------------------------------------------
void PrintLastError()
{
@ -20,7 +13,7 @@ void PrintLastError()
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
std::cout << "ERROR: " << messageBuffer << std::endl;
spdlog::error("{}", messageBuffer);
LocalFree(messageBuffer);
}
}
@ -45,44 +38,19 @@ bool LaunchR5Apex(LAUNCHMODE lMode, LAUNCHSTATE lState)
// Determine launch mode.
switch (lMode)
{
case LAUNCHMODE::LM_DEDI:
{
std::filesystem::path cfgPath = std::filesystem::current_path() /= "platform\\cfg\\startup_dedi.cfg"; // Get cfg path for dedicated startup.
std::ifstream cfgFile(cfgPath); // Read the cfg file.
if (cfgFile.good() && cfgFile) // Does the cfg file exist?
{
std::stringstream ss;
ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream.
CommandLineArguments = ss.str(); // Get all the contents of the cfg file.
}
else
{
std::cout << "*** platform\\cfg\\startup_dedi.cfg does not exist. ***" << std::endl;
cfgFile.close();
return false;
}
cfgFile.close(); // Close cfg file.
WorkerDll = currentDirectory + "\\dedicated.dll"; // Get path to worker dll.
GameDirectory = currentDirectory + "\\r5apex.exe"; // Get path to game executeable.
StartupCommandLine = currentDirectory + "\\r5apex.exe " + CommandLineArguments; // Setup startup command line string.
std::cout << "*** LAUNCHING GAME [DEDICATED] ***" << std::endl;
break;
}
case LAUNCHMODE::LM_DEBUG:
{
std::filesystem::path cfgPath = std::filesystem::current_path() /= "platform\\cfg\\startup_debug.cfg"; // Get cfg path for debug startup.
std::ifstream cfgFile(cfgPath); // Read the cfg file.
if (cfgFile.good() && cfgFile) // Does the cfg file exist?
if (cfgFile.good() && cfgFile) // Does the cfg file exist?
{
std::stringstream ss;
ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream.
CommandLineArguments = ss.str(); // Get all the contents of the cfg file.
ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream.
CommandLineArguments = ss.str(); // Get all the contents of the cfg file.
}
else
{
std::cout << "*** platform\\cfg\\startup_debug.cfg does not exist. ***" << std::endl;
spdlog::error("File 'platform\\cfg\\startup_debug.cfg' does not exist.\n");
cfgFile.close();
return false;
}
@ -92,22 +60,22 @@ bool LaunchR5Apex(LAUNCHMODE lMode, LAUNCHSTATE lState)
GameDirectory = currentDirectory + "\\r5apex.exe"; // Get path to game executeable.
StartupCommandLine = currentDirectory + "\\r5apex.exe " + CommandLineArguments; // Setup startup command line string.
std::cout << "*** LAUNCHING GAME [DEBUG] ***" << std::endl;
spdlog::info("*** LAUNCHING GAME [DEBUG] ***\n");
break;
}
case LAUNCHMODE::LM_GAME:
case LAUNCHMODE::LM_RELEASE:
{
std::filesystem::path cfgPath = std::filesystem::current_path() /= "platform\\cfg\\startup_retail.cfg"; // Get cfg path for release startup.
std::ifstream cfgFile(cfgPath); // Read the cfg file.
if (cfgFile.good() && cfgFile) // Does the cfg file exist?
if (cfgFile.good() && cfgFile) // Does the cfg file exist?
{
std::stringstream ss;
ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream.
CommandLineArguments = ss.str(); // Get all the contents of the cfg file.
ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream.
CommandLineArguments = ss.str(); // Get all the contents of the cfg file.
}
else
{
std::cout << "*** platform\\cfg\\startup_retail.cfg does not exist. ***" << std::endl;
spdlog::error("File 'platform\\cfg\\startup_retail.cfg' does not exist.\n");
cfgFile.close();
return false;
}
@ -117,22 +85,49 @@ bool LaunchR5Apex(LAUNCHMODE lMode, LAUNCHSTATE lState)
GameDirectory = currentDirectory + "\\r5apex.exe"; // Get path to game executeable.
StartupCommandLine = currentDirectory + "\\r5apex.exe " + CommandLineArguments; // Setup startup command line string.
std::cout << "*** LAUNCHING GAME [RELEASE] ***" << std::endl;
spdlog::info("*** LAUNCHING GAME [RELEASE] ***\n");
break;
}
case LAUNCHMODE::LM_DEDI:
{
std::filesystem::path cfgPath = std::filesystem::current_path() /= "platform\\cfg\\startup_dedi.cfg"; // Get cfg path for dedicated startup.
std::ifstream cfgFile(cfgPath); // Read the cfg file.
if (cfgFile.good() && cfgFile) // Does the cfg file exist?
{
std::stringstream ss;
ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream.
CommandLineArguments = ss.str(); // Get all the contents of the cfg file.
}
else
{
spdlog::error("File 'platform\\cfg\\startup_dedi.cfg' does not exist.\n");
cfgFile.close();
return false;
}
cfgFile.close(); // Close cfg file.
WorkerDll = currentDirectory + "\\dedicated.dll"; // Get path to worker dll.
GameDirectory = currentDirectory + "\\r5apex.exe"; // Get path to game executeable.
StartupCommandLine = currentDirectory + "\\r5apex.exe " + CommandLineArguments; // Setup startup command line string.
spdlog::info("*** LAUNCHING GAME [DEDICATED] ***\n");
break;
}
default:
{
std::cout << "*** ERROR: NO LAUNCHMODE SPECIFIED ***" << std::endl;
spdlog::error("*** NO LAUNCH MODE SPECIFIED ***\n");
return false;
}
}
///////////////////////////////////////////////////////////////////////////
// Print the filepaths and arguments.
std::cout << " - CWD: " << currentDirectory << std::endl;
std::cout << " - EXE: " << GameDirectory << std::endl;
std::cout << " - DLL: " << WorkerDll << std::endl;
std::cout << " - CLI: " << CommandLineArguments << std::endl;
// Print the file paths and arguments.
std::cout << "--------------------------------------------------------------------------------------------------------" << std::endl;
spdlog::debug("- CWD: {}\n", currentDirectory);
spdlog::debug("- EXE: {}\n", GameDirectory);
spdlog::debug("- DLL: {}\n", WorkerDll);
spdlog::debug("- CLI: {}\n", CommandLineArguments);
std::cout << "--------------------------------------------------------------------------------------------------------" << std::endl;
///////////////////////////////////////////////////////////////////////////
// Build our list of dlls to inject.
@ -191,16 +186,12 @@ bool LaunchR5Apex(LAUNCHMODE lMode, LAUNCHSTATE lState)
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[], char* envp[])
{
spdlog::set_pattern("[%^%l%$] %v");
spdlog::set_level(spdlog::level::trace);
for (int i = 1; i < argc; ++i)
{
std::string arg = argv[i];
if ((arg == "-dedicated") || (arg == "-dedi"))
{
LaunchR5Apex(LAUNCHMODE::LM_DEDI, LAUNCHSTATE::LS_CHEATS);
Sleep(2000);
return EXIT_SUCCESS;
}
if ((arg == "-debug") || (arg == "-dbg"))
{
LaunchR5Apex(LAUNCHMODE::LM_DEBUG, LAUNCHSTATE::LS_CHEATS);
@ -208,23 +199,33 @@ int main(int argc, char* argv[], char* envp[])
return EXIT_SUCCESS;
}
if ((arg == "-release") || (arg == "-rl"))
if ((arg == "-release") || (arg == "-rel"))
{
LaunchR5Apex(LAUNCHMODE::LM_GAME, LAUNCHSTATE::LS_CHEATS);
LaunchR5Apex(LAUNCHMODE::LM_RELEASE, LAUNCHSTATE::LS_CHEATS);
Sleep(2000);
return EXIT_SUCCESS;
}
if ((arg == "-dedicated") || (arg == "-dedi"))
{
LaunchR5Apex(LAUNCHMODE::LM_DEDI, LAUNCHSTATE::LS_CHEATS);
Sleep(2000);
return EXIT_SUCCESS;
}
}
std::cout << "If you choose Dev as start parameter do not host servers into the Server Browser\n\n"
<< "Every command will be and people can execute any script on your server.\n\n"
<< "Use release for normal playing.\n\n"
<< "Dev should only be used for testing purposes.\n\n";
std::cout << "Enter 1 for Dev Build. Enter 2 for Release Build:\n";
std::cout << "--------------------------------------------------------------------------------------------------------" << std::endl;
spdlog::warn("If DEBUG has been choosen as launch parameter, do not broadcast servers to the Server Browser.\n");
spdlog::warn("All FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY ConVar's/ConCommand's will be enabled.\n");
spdlog::warn("Connected clients will be able to set and execute anything flagged FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY.\n");
std::cout << "--------------------------------------------------------------------------------------------------------" << std::endl;
spdlog::warn("Use DEBUG [1] for development and debugging perposes.\n");
spdlog::warn("Use RELEASE [2] for normal playing and server hosting.\n");
spdlog::warn("Use DEDICATED [3] for running the server only without the client/ui components.\n");
std::cout << "--------------------------------------------------------------------------------------------------------" << std::endl;
spdlog::info("Enter 1 for DEBUG. Enter 2 for RELEASE. Enter 3 for DEDICATED: ");
std::string input = std::string();
if (std::cin >> input)
{
try
@ -238,9 +239,9 @@ int main(int argc, char* argv[], char* envp[])
Sleep(2000);
return EXIT_SUCCESS;
}
case LAUNCHMODE::LM_GAME:
case LAUNCHMODE::LM_RELEASE:
{
LaunchR5Apex(LAUNCHMODE::LM_GAME, LAUNCHSTATE::LS_CHEATS);
LaunchR5Apex(LAUNCHMODE::LM_RELEASE, LAUNCHSTATE::LS_CHEATS);
Sleep(2000);
return EXIT_SUCCESS;
}
@ -252,23 +253,22 @@ int main(int argc, char* argv[], char* envp[])
}
default:
{
std::cout << "R5 Reloaded asked for a number between 1 and 2 :(.\n";
Sleep(2000);
spdlog::error("R5Reloaded requires '1' for DEBUG mode, '2' for RELEASE mode, '3' for DEDICATED mode.\n");
Sleep(5000);
return EXIT_FAILURE;
}
}
}
catch (std::exception& e)
{
std::cout << "R5 Reloaded asked for a number and not a letter or anything of that sort :(. Error: " << e.what() << std::endl;
spdlog::error("R5Reloaded only takes numerical input to launch. Error: {}.\n", e.what());
Sleep(5000);
return EXIT_FAILURE;
}
}
std::cout << "R5 Reloaded needs an input to launch :(.\n";
spdlog::error("R5Reloaded requires numerical input to launch.\n");
Sleep(5000);
return EXIT_FAILURE;
}

View File

@ -6,9 +6,9 @@
enum class LAUNCHMODE : int
{
LM_NULL,
LM_DEBUG, // Debug DLL
LM_GAME, // Release DLL
LM_DEDI // Dedi DLL
LM_DEBUG, // Debug DLL
LM_RELEASE, // Release DLL
LM_DEDI // Dedicated DLL
};
//-----------------------------------------------------------------------------
@ -16,6 +16,7 @@ enum class LAUNCHMODE : int
//-----------------------------------------------------------------------------
enum class LAUNCHSTATE : int
{
LS_NULL,
LS_NOCHEATS, // Disabled cheats
LS_CHEATS, // Enable cheats
LS_DEBUG // Enable debug

1
r5launcher/pch.cpp Normal file
View File

@ -0,0 +1 @@
#include "pch.h"

12
r5launcher/pch.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#pragma message("[LAUNCHER] pre-compiling headers.\n")
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <filesystem>
#include <stdio.h>
#include <Windows.h>
#include <detours.h>
#include "spdlog.h"

View File

@ -52,7 +52,7 @@ END
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "R5 Reloaded.ico"
IDI_ICON1 ICON "r5reloaded.ico"
#endif // German (Germany) resources
/////////////////////////////////////////////////////////////////////////////

View File

@ -81,7 +81,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(SolutionDir)external\detours\include;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)external\detours\include;$(SolutionDir)external\spdlog\include;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)external\detours\libs;$(LibraryPath)</LibraryPath>
<IntDir>$(SolutionDir)build\$(ProjectName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
@ -89,7 +89,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)external\detours\include;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)external\detours\include;$(SolutionDir)external\spdlog\include;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)external\detours\libs;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)build\$(ProjectName)\$(Configuration)\</IntDir>
@ -131,6 +131,8 @@
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -156,6 +158,8 @@
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
<StringPooling>true</StringPooling>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -165,22 +169,27 @@
<AdditionalDependencies>detours.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>del "$(SolutionDir)bin\$(Configuration)\Run R5 Reloaded.exe"
rename "$(TargetPath)" "Run R5 Reloaded.exe"</Command>
<Command>del "$(SolutionDir)bin\$(Configuration)\r5reloaded.exe"
rename "$(TargetPath)" "r5reloaded.exe"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="r5launcher.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="R5 Reloaded.ico" />
<Image Include="r5reloaded.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -18,6 +18,9 @@
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h">
@ -26,6 +29,9 @@
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="r5launcher.rc">
@ -33,7 +39,7 @@
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="R5 Reloaded.ico">
<Image Include="r5reloaded.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>

View File

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 63 KiB