some refactoring

This commit is contained in:
otavepto 2024-04-20 00:52:29 +02:00
parent 2185bb03d6
commit aa53202022
6 changed files with 103 additions and 75 deletions

View File

@ -432,7 +432,8 @@ static int WINAPI Mine_WSAConnect( SOCKET s, const sockaddr *addr, int namelen,
}
}
inline bool file_exists (const std::string& name) {
inline bool file_exists (const std::string& name)
{
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}
@ -472,14 +473,11 @@ static void unredirect_crackdll()
DetourTransactionCommit();
}
HMODULE crack_dll_handle;
static void load_dll()
HMODULE crack_dll_handle{};
static void load_crack_dll()
{
std::string path = get_full_program_path();
path += "crack";
//path += PATH_SEPARATOR;
path += DLL_NAME;
PRINT_DEBUG("Crack file %s", path.c_str());
std::string path(get_full_program_path() + "crack" + DLL_NAME);
PRINT_DEBUG("searching for crack file '%s'", path.c_str());
if (file_exists(path)) {
redirect_crackdll();
crack_dll_handle = LoadLibraryW(utf8_decode(path).c_str());
@ -600,9 +598,11 @@ HINTERNET WINAPI Mine_WinHttpOpenRequest(
#include "dll/settings_parser.h"
static bool network_functions_attached = false;
BOOL WINAPI DllMain( HINSTANCE, DWORD dwReason, LPVOID ) {
BOOL WINAPI DllMain( HINSTANCE, DWORD dwReason, LPVOID )
{
switch ( dwReason ) {
case DLL_PROCESS_ATTACH:
PRINT_DEBUG("experimental DLL_PROCESS_ATTACH");
if (!settings_disable_lan_only()) {
PRINT_DEBUG("Hooking lan only functions");
DetourTransactionBegin();
@ -622,11 +622,12 @@ BOOL WINAPI DllMain( HINSTANCE, DWORD dwReason, LPVOID ) {
DetourTransactionCommit();
network_functions_attached = true;
}
load_dll();
load_crack_dll();
load_dlls();
break;
break;
case DLL_PROCESS_DETACH:
PRINT_DEBUG("experimental DLL_PROCESS_DETACH");
if (network_functions_attached) {
DetourTransactionBegin();
DetourUpdateThread( GetCurrentThread() );
@ -644,15 +645,20 @@ BOOL WINAPI DllMain( HINSTANCE, DWORD dwReason, LPVOID ) {
return TRUE;
}
#else
void set_whitelist_ips(uint32_t *from, uint32_t *to, unsigned num_ips)
{
}
#endif
#else
void set_whitelist_ips(uint32_t *from, uint32_t *to, unsigned num_ips)
{
}
#endif

View File

@ -151,9 +151,10 @@ STEAMAPI_API HSteamUser SteamAPI_GetHSteamUser()
return CLIENT_HSTEAMUSER;
}
STEAMAPI_API ISteamClient *g_pSteamClientGameServer;
#ifndef STEAMCLIENT_DLL
ISteamClient *g_pSteamClientGameServer;
#ifndef STEAMCLIENT_DLL // api
ISteamClient *g_pSteamClientGameServer{};
#else // client
STEAMAPI_API ISteamClient *g_pSteamClientGameServer{};
#endif
static Steam_Client *steamclient_instance;
@ -198,9 +199,9 @@ bool steamclient_has_ipv6_functions()
static void *create_client_interface(const char *ver)
{
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (strstr(ver, "SteamClient") == ver) {
void *steam_client;
void *steam_client = nullptr;
if (strstr(ver, "SteamClient") == ver) {
if (strcmp(ver, "SteamClient007") == 0) {
steam_client = (ISteamClient007 *)get_steam_client();
} else if (strcmp(ver, "SteamClient008") == 0) {
@ -233,14 +234,13 @@ static void *create_client_interface(const char *ver)
steam_client = (ISteamClient *)get_steam_client();
steamclient_has_ipv6_functions_flag = true;
} else {
PRINT_DEBUG("requested unknown steamclient version '%s'", ver);
steam_client = (ISteamClient *)get_steam_client();
steamclient_has_ipv6_functions_flag = true;
}
return steam_client;
} else {
return NULL;
}
return steam_client;
}
STEAMAPI_API void * S_CALLTYPE SteamInternal_CreateInterface( const char *ver )
@ -308,7 +308,7 @@ STEAMAPI_API ESteamAPIInitResult S_CALLTYPE SteamAPI_InitFlat( SteamErrMsg *pOut
// SteamAPI_Init must be called before using any other API functions. If it fails, an
// error message will be output to the debugger (or stderr) with further information.
static HSteamPipe user_steam_pipe;
static HSteamPipe user_steam_pipe = 0;
STEAMAPI_API steam_bool S_CALLTYPE SteamAPI_Init()
{
PRINT_DEBUG_ENTRY();
@ -369,8 +369,10 @@ STEAMAPI_API void S_CALLTYPE SteamAPI_Shutdown()
get_steam_client()->clientShutdown();
get_steam_client()->BReleaseSteamPipe(user_steam_pipe);
get_steam_client()->BShutdownIfAllPipesClosed();
user_steam_pipe = 0;
--global_counter;
old_user_instance = NULL;
old_friends_interface = NULL;
old_utils_interface = NULL;
@ -392,6 +394,7 @@ STEAMAPI_API void S_CALLTYPE SteamAPI_Shutdown()
old_video_instance = NULL;
old_parental_instance = NULL;
old_unified_instance = NULL;
if (global_counter == 0) {
destroy_client();
}
@ -448,7 +451,7 @@ STEAMAPI_API void S_CALLTYPE SteamAPI_ReleaseCurrentThreadMemory()
STEAMAPI_API void S_CALLTYPE SteamAPI_WriteMiniDump( uint32 uStructuredExceptionCode, void* pvExceptionInfo, uint32 uBuildID )
{
PRINT_DEBUG_TODO();
PRINT_DEBUG(" The app is writing a crash dump! [XXXXXXXXXXXXXXXXXXXXXXXXXXX]");
PRINT_DEBUG(" app is writing a crash dump! [XXXXXXXXXXXXXXXXXXXXXXXXXXX]");
}
STEAMAPI_API void S_CALLTYPE SteamAPI_SetMiniDumpComment( const char *pchMsg )
@ -580,7 +583,7 @@ STEAMAPI_API void Steam_RunCallbacks( HSteamPipe hSteamPipe, bool bGameServerCal
// register the callback funcs to use to interact with the steam dll
STEAMAPI_API void Steam_RegisterInterfaceFuncs( void *hModule )
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG_TODO();
}
// returns the HSteamUser of the last user to dispatch a callback
@ -613,7 +616,7 @@ STEAMAPI_API HSteamPipe SteamAPI_GetHSteamPipe()
// sets whether or not Steam_RunCallbacks() should do a try {} catch (...) {} around calls to issuing callbacks
STEAMAPI_API void SteamAPI_SetTryCatchCallbacks( bool bTryCatchCallbacks )
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG_TODO();
}
// backwards compat export, passes through to SteamAPI_ variants
@ -649,181 +652,181 @@ STEAMAPI_API ISteamClient *SteamClient() {
STEAMAPI_API ISteamUser *SteamUser()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_user_instance, get_steam_client_old()->GetISteamUser(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_user))
}
STEAMAPI_API ISteamFriends *SteamFriends()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_friends_interface, get_steam_client_old()->GetISteamFriends(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_friends ))
}
STEAMAPI_API ISteamUtils *SteamUtils()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_utils_interface, get_steam_client_old()->GetISteamUtils(SteamAPI_GetHSteamPipe(), old_utils))
}
STEAMAPI_API ISteamMatchmaking *SteamMatchmaking()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_matchmaking_instance, get_steam_client_old()->GetISteamMatchmaking(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_matchmaking))
}
STEAMAPI_API ISteamUserStats *SteamUserStats()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_userstats_instance, get_steam_client_old()->GetISteamUserStats(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_userstats))
}
STEAMAPI_API ISteamApps *SteamApps()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_apps_instance, get_steam_client_old()->GetISteamApps(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_apps))
}
STEAMAPI_API ISteamMatchmakingServers *SteamMatchmakingServers()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_matchmakingservers_instance, get_steam_client_old()->GetISteamMatchmakingServers(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_matchmaking_servers))
}
STEAMAPI_API ISteamNetworking *SteamNetworking()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_networking_instance, get_steam_client_old()->GetISteamNetworking(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_networking))
}
STEAMAPI_API ISteamRemoteStorage *SteamRemoteStorage()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_remotestorage_instance, get_steam_client_old()->GetISteamRemoteStorage(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_remote_storage_interface))
}
STEAMAPI_API ISteamScreenshots *SteamScreenshots()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_screenshots_instance, get_steam_client_old()->GetISteamScreenshots(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_screenshots))
}
STEAMAPI_API ISteamHTTP *SteamHTTP()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_http_instance, get_steam_client_old()->GetISteamHTTP(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_http))
}
STEAMAPI_API ISteamController *SteamController()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_controller_instance, get_steam_client_old()->GetISteamController(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_controller))
}
STEAMAPI_API ISteamUGC *SteamUGC()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_ugc_instance, get_steam_client_old()->GetISteamUGC(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_ugc_interface ))
}
STEAMAPI_API ISteamAppList *SteamAppList()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_applist_instance, get_steam_client_old()->GetISteamAppList(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_applist))
}
STEAMAPI_API ISteamMusic *SteamMusic()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_music_instance, get_steam_client_old()->GetISteamMusic(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_music))
}
STEAMAPI_API ISteamMusicRemote *SteamMusicRemote()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_musicremote_instance, get_steam_client_old()->GetISteamMusicRemote(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_music_remote))
}
STEAMAPI_API ISteamHTMLSurface *SteamHTMLSurface()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_htmlsurface_instance, get_steam_client_old()->GetISteamHTMLSurface(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_html_surface))
}
STEAMAPI_API ISteamInventory *SteamInventory()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_inventory_instance, get_steam_client_old()->GetISteamInventory(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_inventory))
}
STEAMAPI_API ISteamVideo *SteamVideo()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_video_instance, get_steam_client_old()->GetISteamVideo(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_video))
}
STEAMAPI_API ISteamParentalSettings *SteamParentalSettings()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_parental_instance, get_steam_client_old()->GetISteamParentalSettings(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), ""))
}
STEAMAPI_API ISteamUnifiedMessages *SteamUnifiedMessages()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_unified_instance, get_steam_client_old()->GetISteamUnifiedMessages(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_unified_messages))
}
STEAMAPI_API ISteamGameServer *SteamGameServer()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gameserver_instance, get_steam_clientserver_old()->GetISteamGameServer(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_gameserver ))
}
STEAMAPI_API ISteamUtils *SteamGameServerUtils()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_utils_instance, get_steam_clientserver_old()->GetISteamUtils(SteamGameServer_GetHSteamPipe(), old_utils ))
}
STEAMAPI_API ISteamNetworking *SteamGameServerNetworking()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_networking_instance, get_steam_clientserver_old()->GetISteamNetworking(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_networking ))
}
STEAMAPI_API ISteamGameServerStats *SteamGameServerStats()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_stats_instance, get_steam_clientserver_old()->GetISteamGameServerStats(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_gameserver_stats ))
}
STEAMAPI_API ISteamHTTP *SteamGameServerHTTP()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_http_instance, get_steam_clientserver_old()->GetISteamHTTP(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_http ))
}
STEAMAPI_API ISteamInventory *SteamGameServerInventory()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_inventory_instance, get_steam_clientserver_old()->GetISteamInventory(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_inventory ))
}
STEAMAPI_API ISteamUGC *SteamGameServerUGC()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_ugc_instance, get_steam_clientserver_old()->GetISteamUGC(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_ugc_interface ))
}
STEAMAPI_API ISteamApps *SteamGameServerApps()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_apps_instance, get_steam_clientserver_old()->GetISteamApps(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_apps ))
}
STEAMAPI_API ISteamMasterServerUpdater *SteamMasterServerUpdater()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_masterupdater_instance, get_steam_clientserver_old()->GetISteamMasterServerUpdater(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_masterserver_updater))
}
@ -994,7 +997,7 @@ STEAMAPI_API uint64 SteamGameServer_GetSteamID()
STEAMAPI_API ISteamClient *SteamGameServerClient()
{
PRINT_DEBUG_ENTRY();
PRINT_DEBUG("old");
if (!get_steam_clientserver_old()->IsServerInit()) return NULL;
return (ISteamClient *)SteamInternal_CreateInterface(old_client);
}
@ -1016,11 +1019,11 @@ STEAMAPI_API void S_CALLTYPE SteamAPI_SetBreakpadAppID( uint32 unAppID )
}
struct cb_data {
int cb_id;
std::vector<char> result;
int cb_id{};
std::vector<char> result{};
};
static std::queue<struct cb_data> client_cb;
static std::queue<struct cb_data> server_cb;
static std::queue<struct cb_data> client_cb{};
static std::queue<struct cb_data> server_cb{};
static void cb_add_queue_server(std::vector<char> result, int callback)
{
@ -1183,28 +1186,32 @@ HSteamPipe flat_gs_hsteampipe()
//VR stuff
STEAMAPI_API void *VR_Init(int *error, int type)
{
PRINT_DEBUG_TODO();
if (error) *error = 108; //HmdError_Init_HmdNotFound
return NULL;
}
STEAMAPI_API void *VR_GetGenericInterface( const char *pchInterfaceVersion, int *peError )
{
PRINT_DEBUG_TODO();
return NULL;
}
STEAMAPI_API const char *VR_GetStringForHmdError( int error )
{
PRINT_DEBUG_TODO();
return "";
}
STEAMAPI_API steam_bool VR_IsHmdPresent()
{
PRINT_DEBUG_TODO();
return false;
}
STEAMAPI_API void VR_Shutdown()
{
PRINT_DEBUG_TODO();
}
STEAMAPI_API steam_bool SteamAPI_RestartApp( uint32 appid )
@ -1320,11 +1327,13 @@ STEAMCLIENT_API void Breakpad_SteamSetSteamID( uint64 ulSteamID )
STEAMCLIENT_API void Breakpad_SteamWriteMiniDumpSetComment( const char *pchMsg )
{
PRINT_DEBUG_TODO();
PRINT_DEBUG(" app is writing a crash dump comment! [XXXXXXXXXXXXXXXXXXXXXXXXXXX]");
}
STEAMCLIENT_API void Breakpad_SteamWriteMiniDumpUsingExceptionInfoWithBuildId( int a, int b )
{
PRINT_DEBUG_TODO();
PRINT_DEBUG(" app is writing a crash dump! [XXXXXXXXXXXXXXXXXXXXXXXXXXX]");
}
STEAMCLIENT_API bool Steam_BConnected( HSteamUser hUser, HSteamPipe hSteamPipe )

View File

@ -22,7 +22,7 @@ std::string Settings::sanitize(const std::string &name)
{
// https://github.com/microsoft/referencesource/blob/51cf7850defa8a17d815b4700b67116e3fa283c2/mscorlib/system/io/path.cs#L88C9-L89C1
// https://github.com/microsoft/referencesource/blob/51cf7850defa8a17d815b4700b67116e3fa283c2/mscorlib/system/io/pathinternal.cs#L32
static const char InvalidFileNameChars[] = {
constexpr const static char InvalidFileNameChars[] = {
'\"', '<', '>', '|', '\0',
(char)1, (char)2, (char)3, (char)4, (char)5, (char)6, (char)7, (char)8, (char)9, (char)10,
(char)11, (char)12, (char)13, (char)14, (char)15, (char)16, (char)17, (char)18, (char)19, (char)20,
@ -31,25 +31,31 @@ std::string Settings::sanitize(const std::string &name)
':', '*', '?', /*'\\', '/',*/
};
if (name.empty()) return {};
// we have to use utf-32 because Windows (and probably Linux) allows some chars that need at least 32 bits,
// such as this one (U+1F5FA) called "World Map": https://www.compart.com/en/unicode/U+1F5FA
// utf-16 encoding for these characters require 2 ushort, but we would like to iterate
// over all chars in a linear fashion
std::u32string unicode_name;
std::u32string unicode_name{};
utf8::utf8to32(
name.begin(),
utf8::find_invalid(name.begin(), name.end()), // returns an iterator pointing to the first invalid octet
std::back_inserter(unicode_name));
std::back_inserter(unicode_name)
);
unicode_name.erase(std::remove(unicode_name.begin(), unicode_name.end(), '\n'), unicode_name.end());
unicode_name.erase(std::remove(unicode_name.begin(), unicode_name.end(), '\r'), unicode_name.end());
auto rm_itr = std::remove_if(unicode_name.begin(), unicode_name.end(), [](decltype(unicode_name[0]) ch) {
return ch == '\n' || ch == '\r';
});
if (unicode_name.end() != rm_itr) {
unicode_name.erase(rm_itr, unicode_name.end());
}
auto InvalidFileNameChars_last_it = std::end(InvalidFileNameChars);
for (auto& i : unicode_name)
{
auto found_it = std::find(std::begin(InvalidFileNameChars), InvalidFileNameChars_last_it, i);
for (auto& uch : unicode_name) {
auto found_it = std::find(std::begin(InvalidFileNameChars), InvalidFileNameChars_last_it, uch);
if (found_it != InvalidFileNameChars_last_it) { // if illegal
i = ' ';
uch = ' ';
}
}

View File

@ -223,12 +223,12 @@ Steam_Client::~Steam_Client()
delete ugc_bridge; ugc_bridge = nullptr;
delete network; network = nullptr;
delete run_every_runcb; run_every_runcb = nullptr;
delete callbacks_server; callbacks_server = nullptr;
delete callbacks_client; callbacks_client = nullptr;
delete callback_results_server; callback_results_server = nullptr;
delete callback_results_client; callback_results_client = nullptr;
delete network; network = nullptr;
}
void Steam_Client::userLogIn()

View File

@ -103,13 +103,15 @@ bool common_helpers::ends_with_i(const std::wstring_view &target, const std::wst
std::string common_helpers::string_strip(const std::string_view &str)
{
static constexpr const char whitespaces[] = " \t\r\n";
if (str.empty()) return {};
size_t start = str.find_first_not_of(whitespaces);
size_t end = str.find_last_not_of(whitespaces);
if (start == std::string::npos) return {};
if (start == end) {
if (start == end) { // happens when string is 1 char
auto c = str[start];
for (auto c_white = whitespaces; *c_white; ++c_white) {
if (c == *c_white) return {};
@ -184,6 +186,8 @@ void common_helpers::consume_bom(std::ifstream &input)
std::string common_helpers::to_lower(const std::string_view &str)
{
if (str.empty()) return {};
std::string _str(str.size(), '\0');
std::transform(str.begin(), str.end(), _str.begin(), [](char c) { return std::tolower(c); });
return _str;
@ -191,6 +195,8 @@ std::string common_helpers::to_lower(const std::string_view &str)
std::wstring common_helpers::to_lower(const std::wstring_view &wstr)
{
if (wstr.empty()) return {};
std::wstring _wstr(wstr.size(), '\0');
std::transform(wstr.begin(), wstr.end(), _wstr.begin(), [](wchar_t c) { return std::tolower(c); });
return _wstr;
@ -198,6 +204,8 @@ std::wstring common_helpers::to_lower(const std::wstring_view &wstr)
std::string common_helpers::to_upper(const std::string_view &str)
{
if (str.empty()) return {};
std::string _str(str.size(), '\0');
std::transform(str.begin(), str.end(), _str.begin(), [](char c) { return std::toupper(c); });
return _str;
@ -205,6 +213,8 @@ std::string common_helpers::to_upper(const std::string_view &str)
std::wstring common_helpers::to_upper(const std::wstring_view &wstr)
{
if (wstr.empty()) return {};
std::wstring _wstr(wstr.size(), '\0');
std::transform(wstr.begin(), wstr.end(), _wstr.begin(), [](wchar_t c) { return std::toupper(c); });
return _wstr;

View File

@ -76,10 +76,7 @@ static std::vector<uint8_t> get_pe_header(const std::wstring &filepath)
}
}
static std::vector<std::wstring> collect_dlls_to_inject(
const std::wstring &extra_dlls_folder,
bool is_exe_32,
std::wstring &failed_dlls)
static std::vector<std::wstring> collect_dlls_to_inject(const std::wstring &extra_dlls_folder, bool is_exe_32, std::wstring &failed_dlls)
{
const auto load_order_file = std::filesystem::path(extra_dlls_folder) / "load_order.txt";
std::vector<std::wstring> dlls_to_inject{};