Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add VKBASALT_CONFIG support #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ The config file will be searched for in the following locations:

If you want to make changes for one game only, you can create a file named `vkBasalt.conf` in the working directory of the game and change the values there.

#### Quick override
To override some of the default config options the `VKBASALT_CONFIG` env var can be used, e.g. `VKBASALT_CONFIG='effects=fxaa:cas;casSharpness=1.0'`.
The separator is `;`

#### Reshade Fx shaders

To run reshade fx shaders e.g. shaders from the [reshade repo](https://github.com/crosire/reshade-shaders), you have to set `reshadeTexturePath` and `reshadeIncludePath` to the matching dirctories from the repo. To then use a specific shader you need to set a custom effect name to the shader path and then add that effect name to `effects` like every other effect.
Expand Down
30 changes: 28 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ namespace vkBasalt
const char* tmpConfEnv = std::getenv("VKBASALT_CONFIG_FILE");
std::string customConfigFile = tmpConfEnv ? std::string(tmpConfEnv) : "";

// Custom config string
const char* tmpConfStringEnv = std::getenv("VKBASALT_CONFIG");
std::string customConfigString = tmpConfStringEnv ? std::string(tmpConfStringEnv) : "";

// User config file path
const char* tmpHomeEnv = std::getenv("XDG_DATA_HOME");
std::string userConfigFile = tmpHomeEnv ? std::string(tmpHomeEnv) + "/vkBasalt/vkBasalt.conf"
Expand All @@ -32,18 +36,29 @@ namespace vkBasalt
std::string(DATADIR) + "/vkBasalt/vkBasalt.conf", // legacy system-wide config
};

auto hasConfigFile = false;
for (const auto& cFile : configPath)
{
std::ifstream configFile(cFile);
if (!configFile.good())
continue;

Logger::info("config file: " + cFile);
hasConfigFile = true;
readConfigFile(configFile);
return;
break;
}

if (!hasConfigFile)
{
Logger::err("no good config file");
}

Logger::err("no good config file");
if (!customConfigString.empty())
{
Logger::info("config string: " + customConfigString);
readConfigFromEnv(customConfigString);
}
}

Config::Config(const Config& other)
Expand All @@ -61,6 +76,17 @@ namespace vkBasalt
}
}

void Config::readConfigFromEnv(std::string configLine)
{
std::string line;
std::stringstream stream(configLine);

while (std::getline(stream, line, ';'))
{
readConfigLine(line);
}
}

void Config::readConfigLine(std::string line)
{
std::string key;
Expand Down
1 change: 1 addition & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace vkBasalt

void readConfigLine(std::string line);
void readConfigFile(std::ifstream& stream);
void readConfigFromEnv(std::string configLine);

void parseOption(const std::string& option, int32_t& result);
void parseOption(const std::string& option, float& result);
Expand Down