diff --git a/flplusplus.ini b/flplusplus.ini index 19b768d..c98697e 100644 --- a/flplusplus.ini +++ b/flplusplus.ini @@ -14,6 +14,12 @@ save_folder_name = Freelancer ; save_in_directory ; if true, save in the game directory (EXE/../SAVE) instead of Documents/My Games save_in_directory = false +; screenshots_folder_name +; Name of the screenshots folder in Pictures +screenshots_folder_name = FreelancerShots +; screenshots_in_directory +; if true, screenshots are saved in the game directory (EXE/../SCREENSHOTS) instead of Pictures +screenshots_in_directory = false ; Patch out "Failed to get start location" warning remove_start_location_warning = true ; Log spew to a console window diff --git a/flplusplus/src/config.cpp b/flplusplus/src/config.cpp index af4ddf4..e658a7d 100644 --- a/flplusplus/src/config.cpp +++ b/flplusplus/src/config.cpp @@ -16,6 +16,8 @@ void config::init_defaults() conf.characterdetailscale = 1; conf.savefoldername = "Freelancer"; conf.saveindirectory = false; + conf.screenshotsfoldername = "FreelancerShots"; + conf.screenshotsindirectory = false; conf.removestartlocationwarning = true; conf.logtoconsole = false; conf.shippreviewscrollingspeed = 2; @@ -50,6 +52,12 @@ void config::init_from_file(const char *filename) if (reader.is_value("save_in_directory")) conf.saveindirectory = reader.get_value_bool(0); + if (reader.is_value("screenshots_folder_name")) + conf.screenshotsfoldername = std::string(reader.get_value_string(0)); + + if (reader.is_value("screenshots_in_directory")) + conf.screenshotsindirectory = reader.get_value_bool(0); + if (reader.is_value("remove_start_location_warning")) conf.removestartlocationwarning = reader.get_value_bool(0); diff --git a/flplusplus/src/config.h b/flplusplus/src/config.h index f1a2769..98bf54c 100644 --- a/flplusplus/src/config.h +++ b/flplusplus/src/config.h @@ -15,6 +15,8 @@ namespace config { float characterdetailscale; std::string savefoldername; bool saveindirectory; + std::string screenshotsfoldername; + bool screenshotsindirectory; bool removestartlocationwarning; bool logtoconsole; float shippreviewscrollingspeed; diff --git a/flplusplus/src/screenshot.cpp b/flplusplus/src/screenshot.cpp index c9b47d3..e67d44c 100644 --- a/flplusplus/src/screenshot.cpp +++ b/flplusplus/src/screenshot.cpp @@ -3,19 +3,54 @@ #include "screenshot.h" #include "patch.h" #include "offsets.h" +#include "config.h" +#include "log.h" #define WIN32_LEAN_AND_MEAN #include #include #include #include +#include #include #include +#include +#include using namespace Gdiplus; -typedef bool (*screenshot_path_t)(char * const); -screenshot_path_t GetScreenShotPath; +void HandleScreenShotPathFail(char * const outputBuffer) +{ + *outputBuffer = '\0'; + logger::writeline("flplusplus: failed to access the screenshots directory. Freelancer may not be able to properly store screenshots."); +} + +bool ScreenShotPath(char * const outputBuffer) +{ + char path[MAX_PATH]; + if (config::get_config().screenshotsindirectory) { + GetModuleFileNameA(NULL, path, MAX_PATH); + PathRemoveFileSpecA(path); + PathAppendA(path, "..\\SCREENSHOTS"); + } else { + if (SHGetFolderPathA(NULL, CSIDL_MYPICTURES | CSIDL_FLAG_CREATE, NULL, 0, path) != S_OK) { + HandleScreenShotPathFail(outputBuffer); + return false; + } + + PathAppendA(path, config::get_config().screenshotsfoldername.c_str()); + } + + if (_access(path, 0) != 0) { + if (_mkdir(path) != 0) { + HandleScreenShotPathFail(outputBuffer); + return false; + } + } + + strcpy(outputBuffer, path); + return true; +} std::wstring stows(std::string str) { @@ -55,7 +90,7 @@ int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) static DWORD OnScreenshot() { char directory[MAX_PATH]; - if(!GetScreenShotPath(directory)) + if(!ScreenShotPath(directory)) { return DWORD(-1); } @@ -120,7 +155,8 @@ static DWORD OnScreenshot() void screenshot::init() { HMODULE common = GetModuleHandleA("common.dll"); - GetScreenShotPath = (screenshot_path_t)GetProcAddress(common, "?GetScreenShotPath@@YA_NQAD@Z"); + auto* getScreenShotPath = (unsigned char*)GetProcAddress(common, "?GetScreenShotPath@@YA_NQAD@Z"); unsigned char buffer[5]; patch::detour((unsigned char*)OF_PRINTSCREEN, (void*)OnScreenshot, buffer); + patch::detour(getScreenShotPath, (void*)ScreenShotPath, buffer); }