mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2024-11-27 13:14:01 +08:00
Merge pull request #166 from otavepto/cold-loader-name
allow loading `.ini` file with the same name as the cold client loader exe name
This commit is contained in:
commit
1e2425d48a
@ -1,3 +1,9 @@
|
|||||||
|
* for Windows ColdClientLoader: allow loading `.ini` file with the same name as the loader
|
||||||
|
ex: if the loader is named `game_cold_loader.exe`, then it will first try to load `game_cold_loader.ini`,
|
||||||
|
if that doesn't exist, it will fallback to `ColdClientLoader.ini`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 2024/5/5
|
## 2024/5/5
|
||||||
|
|
||||||
* **[Clompress]** update Turkish translation
|
* **[Clompress]** update Turkish translation
|
||||||
|
@ -383,6 +383,11 @@ size_t pe_helpers::get_pe_size(HMODULE hModule)
|
|||||||
|
|
||||||
static std::wstring path_w{};
|
static std::wstring path_w{};
|
||||||
static std::string path_a{};
|
static std::string path_a{};
|
||||||
|
|
||||||
|
static std::wstring modulename_w{};
|
||||||
|
static std::string modulename_a{};
|
||||||
|
|
||||||
|
|
||||||
const std::string& pe_helpers::get_current_exe_path()
|
const std::string& pe_helpers::get_current_exe_path()
|
||||||
{
|
{
|
||||||
if (path_a.empty()) {
|
if (path_a.empty()) {
|
||||||
@ -409,14 +414,27 @@ const std::wstring& pe_helpers::get_current_exe_path_w()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((read_chars < path_w.size()) && path_w[0]) {
|
if ((read_chars < path_w.size()) && path_w[0]) {
|
||||||
path_w = path_w.substr(0, path_w.find_last_of(L"\\/") + 1);
|
auto modulename_idx = path_w.find_last_of(L"\\/") + 1;
|
||||||
|
modulename_w = path_w.substr(modulename_idx, read_chars - modulename_idx);
|
||||||
|
path_w = path_w.substr(0, modulename_idx);
|
||||||
|
|
||||||
auto cvt_state = std::mbstate_t();
|
{
|
||||||
const wchar_t* src = &path_w[0];
|
auto cvt_state = std::mbstate_t();
|
||||||
size_t conversion_bytes = std::wcsrtombs(nullptr, &src, 0, &cvt_state);
|
const wchar_t* src = &path_w[0];
|
||||||
path_a.resize(conversion_bytes + 1);
|
size_t conversion_bytes = std::wcsrtombs(nullptr, &src, 0, &cvt_state);
|
||||||
std::wcsrtombs(&path_a[0], &src, path_a.size(), &cvt_state);
|
path_a.resize(conversion_bytes + 1);
|
||||||
path_a = path_a.substr(0, conversion_bytes);
|
std::wcsrtombs(&path_a[0], &src, path_a.size(), &cvt_state);
|
||||||
|
path_a = path_a.substr(0, conversion_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto cvt_state = std::mbstate_t();
|
||||||
|
const wchar_t* src = &modulename_w[0];
|
||||||
|
size_t conversion_bytes = std::wcsrtombs(nullptr, &src, 0, &cvt_state);
|
||||||
|
modulename_a.resize(conversion_bytes + 1);
|
||||||
|
std::wcsrtombs(&modulename_a[0], &src, modulename_a.size(), &cvt_state);
|
||||||
|
modulename_a = modulename_a.substr(0, conversion_bytes);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
path_w.clear();
|
path_w.clear();
|
||||||
}
|
}
|
||||||
@ -428,10 +446,28 @@ const std::wstring& pe_helpers::get_current_exe_path_w()
|
|||||||
return path_w;
|
return path_w;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pe_helpers::ends_with_i(PUNICODE_STRING target, const std::wstring &query)
|
const std::string& pe_helpers::get_current_exe_name()
|
||||||
|
{
|
||||||
|
if (modulename_a.empty()) {
|
||||||
|
get_current_exe_path_w();
|
||||||
|
}
|
||||||
|
|
||||||
|
return modulename_a;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::wstring& pe_helpers::get_current_exe_name_w()
|
||||||
|
{
|
||||||
|
if (modulename_w.empty()) {
|
||||||
|
get_current_exe_path_w();
|
||||||
|
}
|
||||||
|
|
||||||
|
return modulename_w;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pe_helpers::ends_with_i(PUNICODE_STRING target, const std::wstring_view &query)
|
||||||
{
|
{
|
||||||
return common_helpers::ends_with_i(
|
return common_helpers::ends_with_i(
|
||||||
std::wstring(target->Buffer, (PWSTR)((char*)target->Buffer + target->Length)),
|
std::wstring_view( target->Buffer, target->Length / sizeof(target->Buffer[0]) ),
|
||||||
query
|
query
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <winternl.h>
|
#include <winternl.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
namespace pe_helpers
|
namespace pe_helpers
|
||||||
{
|
{
|
||||||
@ -44,7 +45,11 @@ const std::string& get_current_exe_path();
|
|||||||
|
|
||||||
const std::wstring& get_current_exe_path_w();
|
const std::wstring& get_current_exe_path_w();
|
||||||
|
|
||||||
bool ends_with_i(PUNICODE_STRING target, const std::wstring &query);
|
const std::string& get_current_exe_name();
|
||||||
|
|
||||||
|
const std::wstring& get_current_exe_name_w();
|
||||||
|
|
||||||
|
bool ends_with_i(PUNICODE_STRING target, const std::wstring_view &query);
|
||||||
|
|
||||||
MEMORY_BASIC_INFORMATION get_mem_page_details(const void* mem);
|
MEMORY_BASIC_INFORMATION get_mem_page_details(const void* mem);
|
||||||
|
|
||||||
|
@ -12,12 +12,13 @@
|
|||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <filesystem>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
static const std::wstring IniFile = pe_helpers::get_current_exe_path_w() + L"ColdClientLoader.ini";
|
static std::wstring IniFile{};
|
||||||
static const std::wstring dbg_file = pe_helpers::get_current_exe_path_w() + L"COLD_LDR_LOG.txt";
|
static const std::wstring dbg_file = pe_helpers::get_current_exe_path_w() + pe_helpers::get_current_exe_name_w() + L".log";
|
||||||
constexpr static const char STEAM_UNIVERSE[] = "Public";
|
constexpr static const char STEAM_UNIVERSE[] = "Public";
|
||||||
constexpr static const char STEAM_URL_PROTOCOL[] = "URL:steam protocol";
|
constexpr static const char STEAM_URL_PROTOCOL[] = "URL:steam protocol";
|
||||||
|
|
||||||
@ -339,9 +340,16 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
|
|||||||
{
|
{
|
||||||
dbg_log::init(dbg_file.c_str());
|
dbg_log::init(dbg_file.c_str());
|
||||||
|
|
||||||
|
IniFile = pe_helpers::get_current_exe_path_w() + std::filesystem::path(pe_helpers::get_current_exe_name_w()).stem().wstring() + L".ini";
|
||||||
|
dbg_log::write(L"Searching for configuration file: " + IniFile);
|
||||||
if (!common_helpers::file_exist(IniFile)) {
|
if (!common_helpers::file_exist(IniFile)) {
|
||||||
dbg_log::write(L"Couldn't find the configuration file: " + dbg_file);
|
IniFile = pe_helpers::get_current_exe_path_w() + L"ColdClientLoader.ini";
|
||||||
MessageBoxA(NULL, "Couldn't find the configuration file ColdClientLoader.ini.", "ColdClientLoader", MB_ICONERROR);
|
dbg_log::write(L"Searching for configuration file: " + IniFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!common_helpers::file_exist(IniFile)) {
|
||||||
|
dbg_log::write(L"Couldn't find the configuration file");
|
||||||
|
MessageBoxA(NULL, "Couldn't find the configuration file.", "ColdClientLoader", MB_ICONERROR);
|
||||||
dbg_log::close();
|
dbg_log::close();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user