From 0358bcae89c5fc7c018b623bc3c9ddd00ed7e8d1 Mon Sep 17 00:00:00 2001 From: otavepto <153766569+otavepto@users.noreply.github.com> Date: Sun, 7 Jan 2024 15:43:53 +0200 Subject: [PATCH] parse the crash printer path from config file --- CHANGELOG.md | 5 +++ dll/dll/common_includes.h | 17 ++++++++ dll/settings_parser.cpp | 41 +++++++++++++------ post_build/README.release.md | 14 +++++++ .../crash_printer_location.EXAMPLE.txt | 1 + 5 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 post_build/steam_settings.EXAMPLE/crash_printer_location.EXAMPLE.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 98868710..9c9e924d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +* added a very basic crashes logger/printer, enabled by creating a file called `crash_printer_location.txt` inside the `steam_settings` folder, + check README.realease.md for more details + +--- + ## 2024/1/5 * **[Detanup01]** Fixed parsing of old Steam interfaces, reported by **[LuKeStorm]**: https://cs.rin.ru/forum/viewtopic.php?p=2971639#p2971639 diff --git a/dll/dll/common_includes.h b/dll/dll/common_includes.h index 98e0e939..8f86518a 100644 --- a/dll/dll/common_includes.h +++ b/dll/dll/common_includes.h @@ -98,6 +98,8 @@ #include "detours/detours.h" #endif + #include "crash_printer/win.hpp" + // Convert a wide Unicode string to an UTF8 string static inline std::string utf8_encode(const std::wstring &wstr) { @@ -149,6 +151,8 @@ static inline void reset_LastError() #include #include + #include "crash_printer/linux.hpp" + #define PATH_MAX_STRING_SIZE 512 #define PATH_SEPARATOR "/" #define utf8_decode(a) a @@ -236,6 +240,17 @@ static std::string uint8_vector_to_hex_string(std::vector& v) return result; } +static inline void consume_bom(std::ifstream &input) +{ + int bom[3]; + bom[0] = input.get(); + bom[1] = input.get(); + bom[2] = input.get(); + if (bom[0] != 0xEF || bom[1] != 0xBB || bom[2] != 0xBF) { + input.seekg(-3, std::ios::cur); + } +} + // Emulator includes // add them here after the inline functions definitions #include "net.pb.h" @@ -261,4 +276,6 @@ static std::string uint8_vector_to_hex_string(std::vector& v) #define LOBBY_CONNECT_APPID ((uint32)-2) +constexpr const char * const whitespaces = " \t\r\n"; + #endif//__INCLUDED_COMMON_INCLUDES__ diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index dbeeb1f8..1a908229 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -17,17 +17,6 @@ #include "dll/settings_parser.h" -static void consume_bom(std::ifstream &input) -{ - int bom[3]; - bom[0] = input.get(); - bom[1] = input.get(); - bom[2] = input.get(); - if (bom[0] != 0xEF || bom[1] != 0xBB || bom[2] != 0xBF) { - input.seekg(0); - } -} - static void load_custom_broadcasts(std::string broadcasts_filepath, std::set &custom_broadcasts) { PRINT_DEBUG("Broadcasts file path: %s\n", broadcasts_filepath.c_str()); @@ -773,7 +762,6 @@ static void parse_force_branch_name(class Settings *settings_client, Settings *s std::string line; getline( input, line ); - constexpr const char * const whitespaces = " \t\r\n"; size_t start = line.find_first_not_of(whitespaces); size_t end = line.find_last_not_of(whitespaces); line = start == end @@ -953,6 +941,33 @@ static void parse_build_id(int &build_id, std::string &steam_settings_path) } } +// crash_printer_location.txt +static void parse_crash_printer_location() +{ + std::string installed_apps_list_path = Local_Storage::get_game_settings_path() + "crash_printer_location.txt"; + std::ifstream input( utf8_decode(installed_apps_list_path) ); + if (input.is_open()) { + consume_bom(input); + std::string line; + std::getline( input, line ); + + size_t start = line.find_first_not_of(whitespaces); + size_t end = line.find_last_not_of(whitespaces); + line = start == end + ? std::string() + : line.substr(start, end - start + 1); + + if (!line.empty()) { + auto crash_path = utf8_decode(get_full_program_path() + line); + if (crash_printer::init(crash_path)) { + PRINT_DEBUG("Unhandled crashes will be saved to '%s'\n", line.c_str()); + } else { + PRINT_DEBUG("Failed to setup unhandled crash printer with path: '%s'\n", line.c_str()); + } + } + } +} + uint32 create_localstorage_settings(Settings **settings_client_out, Settings **settings_server_out, Local_Storage **local_storage_out) { std::string program_path = Local_Storage::get_program_path(); @@ -960,6 +975,8 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s PRINT_DEBUG("Current Path %s save_path: %s\n", program_path.c_str(), save_path.c_str()); + parse_crash_printer_location(); + uint32 appid = parse_steam_app_id(program_path); bool local_save = parse_local_save(program_path, save_path); diff --git a/post_build/README.release.md b/post_build/README.release.md index 410cbe8b..d16d5f15 100644 --- a/post_build/README.release.md +++ b/post_build/README.release.md @@ -364,6 +364,20 @@ Check the relevant files `is_beta_branch.txt` and `force_branch_name.txt` in the --- +## Crash log/printer: + +The emu can setup a very basic crash logger/printer. +This is intended to debug some annoying scenarios, and best used with the debug build of the emu. + +To enable this feature create a file called `crash_printer_location.txt` inside your `steam_settings` folder, +and set the path to the crash log file on a single line. + +Note that forward slashes `/` are encouraged for both Windows & Linux. + +Check the example file `crash_printer_location.EXAMPLE.txt` + +--- + ## Fake Windows dll/exe certificate and antivirus software: The Windows build is signed with a fake self-signed certificate, this helps in bypassing some basic checks by apps, diff --git a/post_build/steam_settings.EXAMPLE/crash_printer_location.EXAMPLE.txt b/post_build/steam_settings.EXAMPLE/crash_printer_location.EXAMPLE.txt new file mode 100644 index 00000000..b93173af --- /dev/null +++ b/post_build/steam_settings.EXAMPLE/crash_printer_location.EXAMPLE.txt @@ -0,0 +1 @@ +./path/relative/to/dll/crashes.txt \ No newline at end of file