Config: Add support for steamid based configurations.

This will be useful for keying specific executables to steamids.
This is sadly required because a bunch of games end up naming themselves
"game.exe" so we can't safely enable thunks for all things shipping a
generic name.
This commit is contained in:
Ryan Houdek committed 2022-11-17 18:27:42 -08:00
1 parent 181d315d2c
commit 432b7d2dc8
5 files changed
+62 -14

No files matched your search

+10 -6
View File
@@ -211,10 +211,12 @@ namespace JSON {
static std::map<FEXCore::Config::LayerType, std::unique_ptr<FEXCore::Config::Layer>> ConfigLayers;
static FEXCore::Config::Layer *Meta{};
constexpr std::array<FEXCore::Config::LayerType, 7> LoadOrder = {
constexpr std::array<FEXCore::Config::LayerType, 9> LoadOrder = {
FEXCore::Config::LayerType::LAYER_GLOBAL_MAIN,
FEXCore::Config::LayerType::LAYER_MAIN,
FEXCore::Config::LayerType::LAYER_GLOBAL_STEAM_APP,
FEXCore::Config::LayerType::LAYER_GLOBAL_APP,
FEXCore::Config::LayerType::LAYER_LOCAL_STEAM_APP,
FEXCore::Config::LayerType::LAYER_LOCAL_APP,
FEXCore::Config::LayerType::LAYER_ARGUMENTS,
FEXCore::Config::LayerType::LAYER_ENVIRONMENT,
@@ -629,7 +631,7 @@ namespace JSON {
class AppLoader final : public FEXCore::Config::OptionMapper {
public:
explicit AppLoader(const std::string& Filename, bool Global);
explicit AppLoader(const std::string& Filename, FEXCore::Config::LayerType Type);
void Load();
private:
@@ -681,8 +683,10 @@ namespace JSON {
});
}
AppLoader::AppLoader(const std::string& Filename, bool Global)
: FEXCore::Config::OptionMapper(Global ? FEXCore::Config::LayerType::LAYER_GLOBAL_APP : FEXCore::Config::LayerType::LAYER_LOCAL_APP) {
AppLoader::AppLoader(const std::string& Filename, FEXCore::Config::LayerType Type)
: FEXCore::Config::OptionMapper(Type) {
const bool Global = Type == FEXCore::Config::LayerType::LAYER_GLOBAL_STEAM_APP ||
Type == FEXCore::Config::LayerType::LAYER_LOCAL_STEAM_APP;
Config = FEXCore::Config::GetApplicationConfig(Filename, Global);
// Immediately load so we can reload the meta layer
@@ -754,8 +758,8 @@ namespace JSON {
}
}
std::unique_ptr<FEXCore::Config::Layer> CreateAppLayer(const std::string& Filename, bool Global) {
return std::make_unique<FEXCore::Config::AppLoader>(Filename, Global);
std::unique_ptr<FEXCore::Config::Layer> CreateAppLayer(const std::string& Filename, FEXCore::Config::LayerType Type) {
return std::make_unique<FEXCore::Config::AppLoader>(Filename, Type);
}
std::unique_ptr<FEXCore::Config::Layer> CreateEnvironmentLayer(char *const _envp[]) {
+3 -1
View File
@@ -74,7 +74,9 @@ namespace Handler {
LAYER_GLOBAL_MAIN, ///< /usr/share/fex-emu/Config.json by default
LAYER_MAIN,
LAYER_ARGUMENTS,
LAYER_GLOBAL_STEAM_APP,
LAYER_GLOBAL_APP,
LAYER_LOCAL_STEAM_APP,
LAYER_LOCAL_APP,
LAYER_ENVIRONMENT,
LAYER_TOP,
@@ -272,7 +274,7 @@ namespace Type {
*
* @return unique_ptr for that layer
*/
FEX_DEFAULT_VISIBILITY std::unique_ptr<FEXCore::Config::Layer> CreateAppLayer(const std::string& Filename, bool Global);
FEX_DEFAULT_VISIBILITY std::unique_ptr<FEXCore::Config::Layer> CreateAppLayer(const std::string& Filename, FEXCore::Config::LayerType Type);
/**
* @brief iCreate an environment configuration loader
+12 -2
View File
@@ -109,8 +109,18 @@ namespace FEX::Config {
}
}
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, true));
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, false));
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, FEXCore::Config::LayerType::LAYER_GLOBAL_APP));
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, FEXCore::Config::LayerType::LAYER_LOCAL_APP));
auto SteamID = getenv("SteamAppId");
if (SteamID) {
// If a SteamID exists then let's search for Steam application configs as well.
// We want to key off both the SteamAppId number /and/ the executable since we may not want to thunk all binaries.
auto SteamAppName = fmt::format("Steam_{}_{}", SteamID, ProgramName.string());
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(SteamAppName, FEXCore::Config::LayerType::LAYER_GLOBAL_STEAM_APP));
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(SteamAppName, FEXCore::Config::LayerType::LAYER_LOCAL_STEAM_APP));
}
return std::make_pair(Program, ProgramName);
}
return {};
+26 -3
View File
@@ -249,17 +249,40 @@ FileManager::FileManager(FEXCore::Context::Context *ctx)
}
};
// We try to load ThunksDB from {FEX global config, FEX user config, Defined ThunksConfig option, AppConfig Global, AppConfig Local}
// We try to load ThunksDB from:
// - FEX global config
// - FEX user config
// - Defined ThunksConfig option
// - Steam AppConfig Global
// - AppConfig Global
// - Steam AppConfig Local
// - AppConfig Local
// This doesn't support the classic thunks interface.
auto AppName = AppConfigName();
std::vector<std::string> ConfigPaths {
FEXCore::Config::GetConfigFileLocation(true),
FEXCore::Config::GetConfigFileLocation(false),
ThunkConfigFile,
FEXCore::Config::GetApplicationConfig(AppConfigName(), true),
FEXCore::Config::GetApplicationConfig(AppConfigName(), false),
};
auto SteamID = getenv("SteamAppId");
if (SteamID) {
// If a SteamID exists then let's search for Steam application configs as well.
// We want to key off both the SteamAppId number /and/ the executable since we may not want to thunk all binaries.
auto SteamAppName = fmt::format("Steam_{}_{}", SteamID, AppName);
// Steam application configs interleaved with non-steam for priority sorting.
ConfigPaths.emplace_back(FEXCore::Config::GetApplicationConfig(SteamAppName, true));
ConfigPaths.emplace_back(FEXCore::Config::GetApplicationConfig(AppName, true));
ConfigPaths.emplace_back(FEXCore::Config::GetApplicationConfig(SteamAppName, false));
ConfigPaths.emplace_back(FEXCore::Config::GetApplicationConfig(AppName, false));
}
else {
ConfigPaths.emplace_back(FEXCore::Config::GetApplicationConfig(AppName, true));
ConfigPaths.emplace_back(FEXCore::Config::GetApplicationConfig(AppName, false));
}
for (const auto &Path : ConfigPaths) {
std::vector<char> FileData;
if (LoadFile(FileData, Path)) {
+11 -2
View File
@@ -40,8 +40,17 @@ int main(int argc, char **argv, char **envp) {
if (Options.is_set_by_user("app")) {
// Load the application config if one was provided
auto ProgramName = std::filesystem::path(Options["app"]).filename();
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, true));
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, false));
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, FEXCore::Config::LayerType::LAYER_GLOBAL_APP));
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, FEXCore::Config::LayerType::LAYER_LOCAL_APP));
auto SteamID = getenv("SteamAppId");
if (SteamID) {
// If a SteamID exists then let's search for Steam application configs as well.
// We want to key off both the SteamAppId number /and/ the executable since we may not want to thunk all binaries.
auto SteamAppName = fmt::format("Steam_{}_{}", SteamID, ProgramName.string());
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(SteamAppName, FEXCore::Config::LayerType::LAYER_GLOBAL_STEAM_APP));
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(SteamAppName, FEXCore::Config::LayerType::LAYER_LOCAL_STEAM_APP));
}
}
// Reload the meta layer