Skip to content

Commit

Permalink
Add configurable screenshots folder
Browse files Browse the repository at this point in the history
Resolves #12.
  • Loading branch information
BC46 committed Aug 10, 2024
1 parent 7adaaf8 commit d773ea8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
6 changes: 6 additions & 0 deletions flplusplus.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions flplusplus/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions flplusplus/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace config {
float characterdetailscale;
std::string savefoldername;
bool saveindirectory;
std::string screenshotsfoldername;
bool screenshotsindirectory;
bool removestartlocationwarning;
bool logtoconsole;
float shippreviewscrollingspeed;
Expand Down
44 changes: 40 additions & 4 deletions flplusplus/src/screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.h>
#include <ctime>
#include <string>
#include <shlwapi.h>
#include <shlobj.h>
#include <gdiplus.h>
#include <wchar.h>
#include <io.h>
#include <direct.h>

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)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

0 comments on commit d773ea8

Please sign in to comment.