diff --git a/post-install.md b/post-install.md index a6730d5..f3c33f7 100644 --- a/post-install.md +++ b/post-install.md @@ -2,22 +2,6 @@ This document provides information on additional steps you may want to take after installing Mod Organizer 2. -## Running the original game launcher - -1. Open Mod Organizer 2; -2. Click on the cogwheel in the top bar to configure executables: - -![topbar executables config](screenshots/topbar_executables_config.png?raw=true "Executables Configuration") - -3. Click on the launcher in the list to the left; -4. In the "Binary" text box, add an underscore before the name of the .exe file: - -![executables list](screenshots/executables_config_leftside_list.png?raw=true "Executables List") - -5. Now you should be able to run the launcher by selecting it in the executables dropdown: - -![executables dropdown](screenshots/executables_dropdown.png?raw=true "Executables Dropdown") - ## Using alternative proton versions **IMPORTANT:** Proton 9.0 is the most extensively tested version. The author of this document provides no guarantees that alternative versions will work well. diff --git a/screenshots/executables_config_leftside_list.png b/screenshots/executables_config_leftside_list.png deleted file mode 100644 index 155a6cb..0000000 Binary files a/screenshots/executables_config_leftside_list.png and /dev/null differ diff --git a/screenshots/executables_dropdown.png b/screenshots/executables_dropdown.png deleted file mode 100644 index a30f85b..0000000 Binary files a/screenshots/executables_dropdown.png and /dev/null differ diff --git a/screenshots/topbar_executables_config.png b/screenshots/topbar_executables_config.png deleted file mode 100644 index dfe15cb..0000000 Binary files a/screenshots/topbar_executables_config.png and /dev/null differ diff --git a/steam-redirector/Makefile b/steam-redirector/Makefile index 54d8eb5..c0116b3 100644 --- a/steam-redirector/Makefile +++ b/steam-redirector/Makefile @@ -15,4 +15,4 @@ main.exe: $(WIN_SRC) $(WIN_C) $(WIN_FLAGS) -mwindows -o main.exe $^ main_debug.exe: $(WIN_SRC) - $(WIN_C) $(WIN_FLAGS) -o main_debug.exe $^ + $(WIN_C) $(WIN_FLAGS) -D DEBUG -o main_debug.exe $^ diff --git a/steam-redirector/main.c b/steam-redirector/main.c index 6d6d0e7..c7b192c 100644 --- a/steam-redirector/main.c +++ b/steam-redirector/main.c @@ -26,7 +26,7 @@ char_t* read_path_from_file(const char* file_path) { FILE* file = fopen(file_path, "r"); if (errno != 0) { - fprintf(stderr, "ERROR: failed to open '%s' - %s\n", file_path, strerror(errno)); + fprintf(stderr, "ERROR: failed to open '"PATHSUBST"' - %s\n", file_path, strerror(errno)); return NULL; } @@ -34,7 +34,7 @@ char_t* read_path_from_file(const char* file_path) { size_t estimated_line_length = ftell(file); if (estimated_line_length == 0) { - fprintf(stderr, "ERROR: cannot read empty file '%s'\n", MO2_PATH_FILE); + fprintf(stderr, "ERROR: cannot read empty file '"PATHSUBST"'\n", MO2_PATH_FILE); return NULL; } @@ -52,15 +52,38 @@ char_t* read_path_from_file(const char* file_path) { fclose(file); -#ifdef REQUIRE_UNICODE_CONVERSION - char_t* converted_line = convert_from_unicode(line); +#ifdef _WIN32 + char_t* wline = convert_utf8_to_wchar(line); free(line); - return converted_line; + return wline; #else return line; #endif } +char_t* get_original_launcher(const char_t* redirector_path) { + const char_t* filename = 0; + size_t filename_len = 0; + for (size_t i = 0; redirector_path[i] != '\0'; i++) { + if (redirector_path[i] == PATH_SEPARATOR) { + filename = redirector_path+i+1; + filename_len = 0; + } else { + filename_len++; + } + } + + char_t* original_path = (char_t*)malloc(sizeof(char_t)*(filename_len+2)); + + original_path[0] = '_'; + for (size_t i = 0; i < filename_len; i++) { + original_path[i+1] = filename[i]; + } + original_path[filename_len+1] = '\0'; + + return original_path; +} + int check_file_access(const char_t* path) { errno = 0; check_can_execute(path); @@ -72,48 +95,47 @@ int check_file_access(const char_t* path) { } } -int execute_from_path_file(const char* path_file_location, const char_t* arg) { +int MAIN(argc, argv) { int exit_status = 1; - char_t* executable_path = read_path_from_file(path_file_location); - if (executable_path == NULL) { + char_t *arg = NULL; + if (argc > 1) { + arg = argv[1]; + } + + char_t *exe_path = NULL; + if (getenv("NO_REDIRECT") == NULL) { + putenv("NO_REDIRECT=1"); + exe_path = read_path_from_file(MO2_PATH_FILE); + } else { + exe_path = get_original_launcher(argv[0]); + } + + if (exe_path == NULL) { fprintf(stderr, "ERROR: could not find executable, aborting\n"); goto exit_point; } - fprintf(stdout, "INFO: read executable location '%s'\n", executable_path); - int has_access = check_file_access(executable_path); + int has_access = check_file_access(exe_path); if (has_access == 0) { - fprintf(stderr, "ERROR: cannot execute '%s' - %s\n", executable_path, strerror(errno)); + fprintf(stderr, "ERROR: cannot execute '"PATHSUBST"' - %s\n", exe_path, strerror(errno)); goto exit_point; } - fprintf(stdout, "Launching '%s'\n", executable_path); - execute(executable_path, arg); + fprintf(stdout, "Launching '"PATHSUBST"'\n", exe_path); + execute(exe_path, arg); exit_status = 0; -exit_point: - if (executable_path != NULL) { - free(executable_path); - } - - return exit_status; -} - -#ifdef REQUIRE_UNICODE_CONVERSION -int wmain(int argc, wchar_t** argv) { -#else -int main(int argc, char** argv) { +#ifdef DEBUG + fprintf(stdout, "DEBUG: Process finished, press enter to exit\n"); + getchar(); #endif - int exit_status = 1; - char_t *arg = NULL; - if (argc > 1) { - arg = argv[1]; +exit_point: + if (exe_path != NULL) { + free(exe_path); } - - exit_status = execute_from_path_file(MO2_PATH_FILE, arg); - return exit_status; } + diff --git a/steam-redirector/unix_utils.h b/steam-redirector/unix_utils.h index ced319f..a105235 100644 --- a/steam-redirector/unix_utils.h +++ b/steam-redirector/unix_utils.h @@ -1,5 +1,11 @@ #pragma once +#define PATH_SEPARATOR '/' + +#define PATHSUBST "%s" + +#define MAIN(argc, argv) main(int argc, char** argv) + typedef char char_t; void execute(const char_t* path, const char_t* arg); diff --git a/steam-redirector/win32_utils.c b/steam-redirector/win32_utils.c index 73a3f22..c87f2a1 100644 --- a/steam-redirector/win32_utils.c +++ b/steam-redirector/win32_utils.c @@ -27,7 +27,7 @@ void log_conversion_error() { } } -char_t* convert_from_unicode(const char* str) { +char_t* convert_utf8_to_wchar(const char* str) { int character_count = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); char_t* converted_str = (char_t*)malloc((character_count + 1) * sizeof(char_t)); int bytes_written = MultiByteToWideChar(CP_UTF8, 0, str, -1, converted_str, character_count); @@ -39,3 +39,4 @@ char_t* convert_from_unicode(const char* str) { return converted_str; } + diff --git a/steam-redirector/win32_utils.h b/steam-redirector/win32_utils.h index 784eab2..f77857e 100644 --- a/steam-redirector/win32_utils.h +++ b/steam-redirector/win32_utils.h @@ -2,7 +2,11 @@ #include -#define REQUIRE_UNICODE_CONVERSION +#define PATH_SEPARATOR '\\' + +#define PATHSUBST "%ls" + +#define MAIN(argc, argv) wmain(int argc, wchar_t** argv) typedef wchar_t char_t; @@ -12,5 +16,5 @@ void check_can_execute(const char_t* path); char_t read_character(FILE* file); -char_t* convert_from_unicode(const char* str); +char_t* convert_utf8_to_wchar(const char* str);