Skip to content

Commit

Permalink
Add ValidateScreenshotLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Mar 4, 2024
1 parent c4aaa75 commit 8bd97a1
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
set(NAME "po3_Tweaks" CACHE STRING "")
set(VERSION 1.8.2 CACHE STRING "")
set(VERSION 1.9.0 CACHE STRING "")
set(AE_VERSION 1)
set(VR_VERSION 2)

Expand Down
1 change: 1 addition & 0 deletions cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(sources ${sources}
src/Fixes/ToggleGlobalAI.cpp
src/Fixes/UnderwaterCamera.cpp
src/Fixes/UseFurnitureInCombat.cpp
src/Fixes/ValidateScreenshotFolder.cpp
src/PCH.cpp
src/Papyrus.cpp
src/Settings.cpp
Expand Down
6 changes: 5 additions & 1 deletion src/Fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ void Fixes::PostPostLoad::Install()
void Fixes::DataLoaded::Install()
{
logger::info("\t[FIXES]");
const auto& fixes = Settings::GetSingleton()->GetFixes();

FlagSpellsAsNoAbsorb::Install();

const auto& fixes = Settings::GetSingleton()->GetFixes();
if (fixes.breathingSounds) {
BreathingSounds::Install();
}

if (fixes.validateScreenshotFolder) {
ValidateScreenshotFolder::Install();
}
}
5 changes: 5 additions & 0 deletions src/Fixes.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,9 @@ namespace Fixes
{
void Install();
}

namespace ValidateScreenshotFolder
{
void Install();
}
}
69 changes: 69 additions & 0 deletions src/Fixes/ValidateScreenshotFolder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "Fixes.h"
#include "Settings.h"

//validates default screenshot path
//defaults to game dir/Screenshots if path doesn't exist

namespace Fixes::ValidateScreenshotFolder
{
bool has_root_directory(const std::filesystem::path& a_path)
{
auto path = a_path.string();
return path.contains(":\\") || path.contains(":/");
}

void Install()
{
if (auto setting = RE::GetINISetting("sScreenShotBaseName:Display")) {
std::filesystem::path screenshotFolder;
std::string newBaseName;

auto folder = setting->GetString();
bool emptyPath = string::is_empty(folder);

if (emptyPath) {
screenshotFolder = std::filesystem::current_path();
newBaseName = "Screenshot";
} else {
screenshotFolder = folder;
screenshotFolder.make_preferred();

if (has_root_directory(screenshotFolder)) {
if (!std::filesystem::exists(screenshotFolder)) {
newBaseName = "Screenshot";
}
} else {
// folder will be generated in skyrim root
screenshotFolder = std::filesystem::current_path() /= screenshotFolder;
screenshotFolder.remove_filename();
}
}

if (!newBaseName.empty()) {
//to-do: port this to clib
if (setting->data.s) {
RE::free(setting->data.s);
}

std::size_t strLen = newBaseName.length() + 1;
setting->data.s = RE::malloc<char>(strLen);
std::memcpy(setting->data.s, newBaseName.c_str(), sizeof(char) * strLen);

if (emptyPath) {
RE::ConsoleLog::GetSingleton()->Print("[po3 Tweaks] sScreenShotBaseName:Display ini setting is empty");
} else {
RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Screenshot folder ({}) does not exist", screenshotFolder.string()).c_str());
}
RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Defaulting to {} folder\n", std::filesystem::current_path().string()).c_str());
if (emptyPath) {
logger::info("\t\tValidated screenshot location ({})"sv, screenshotFolder.string());
} else {
logger::info("\t\tValidated screenshot location ({} -> {})"sv, screenshotFolder.string(), std::filesystem::current_path().string());
}
} else {
RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Screenshot folder ({}) validated successfully\n", screenshotFolder.string()).c_str());
logger::info("\t\tValidated screenshot location ({})"sv, screenshotFolder.string());
}
}
}
}
1 change: 1 addition & 0 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void Settings::Fixes::Load(CSimpleIniA& a_ini)
get_value(a_ini, toggleGlobalAIFix, section, "Toggle Global AI Fix", ";TAI console command/Debug.ToggleAI() now toggles all loaded NPC AI");
get_value(a_ini, useFurnitureInCombat, section, "Use Furniture In Combat", ";Use furniture in combat and prevent getting forced out of furniture when attacked.\n;0 - off, 1 - player only, 2 - player and NPCs");
get_value(a_ini, breathingSounds, section, "Breathing Sounds", ";Fix creature breathing sounds persisting after cell change");
get_value(a_ini, validateScreenshotFolder, section, "Validate Screenshot Location", ";Validates game screenshot location.\n;Defaults to Skyrim root directory if sScreenshotBaseName ini setting is empty or folder path does not exist");
get_value(a_ini, loadEditorIDs, section, "Load EditorIDs", ";Loads editorIDs for skipped forms at runtime");
#ifdef SKYRIMVR
get_value(a_ini, fixVRCrosshairRefEvent, section, "VR CrosshairRefEvent Fix", "; Trigger CrossHairRefEvent with hand selection (normally requires game controller to enable crosshair events)");
Expand Down
3 changes: 2 additions & 1 deletion src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class Settings : public ISingleton<Settings>
bool skinnedDecalDelete{ true };
bool jumpingBonusFix{ true };
bool toggleGlobalAIFix{ true };
bool breathingSounds{ true };
std::uint32_t useFurnitureInCombat{ 1 };
bool breathingSounds{ true };
bool validateScreenshotFolder{ true };
bool loadEditorIDs{ true };
#ifdef SKYRIMVR
bool fixVRCrosshairRefEvent{ true };
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "po3tweaks",
"version-string": "1.8.2",
"version-string": "1.9.0",
"description": "Collection of bug fixes and tweaks for Skyrim SE/AE/VR",
"homepage": "https://github.com/powerof3/po3-Tweaks/",
"license": "MIT",
Expand Down

0 comments on commit 8bd97a1

Please sign in to comment.