Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
Support external ini file
  • Loading branch information
RealIndica committed Jul 13, 2022
1 parent e3c0bfd commit a1a4d4d
Show file tree
Hide file tree
Showing 59 changed files with 9,914 additions and 971 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "external/FidelityFX-FSR2"]
path = external/FidelityFX-FSR2
url = https://github.com/GPUOpen-Effects/FidelityFX-FSR2.git
[submodule "external/simpleini"]
path = external/simpleini
url = https://github.com/brofield/simpleini
148 changes: 148 additions & 0 deletions CyberFSR/Config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#include "pch.h"
#include "Config.h"
#include "Util.h"

Config::Config(std::string fileName)
{
absoluteFileName = Util::DllPath().parent_path() / fileName;

Reload();
}

void Config::Reload()
{
if (ini.LoadFile(absoluteFileName.c_str()) == SI_OK)
{
// Depth
DepthInverted = readBool("Depth", "DepthInverted");

// Color
AutoExposure = readBool("Color", "AutoExposure");
HDR = readBool("Color", "HDR");

// MotionVectors
JitterCancellation = readBool("MotionVectors", "JitterCancellation");
DisplayResolution = readBool("MotionVectors", "DisplayResolution");

// Sharpening
EnableSharpening = readBool("Sharpening", "EnableSharpening");
Sharpness = readFloat("Sharpening", "Sharpness");
SharpnessRange = readSharpnessRange("Sharpening", "SharpnessRange");

//Upscale Ratio Override
UpscaleRatioOverrideEnabled = readBool("UpscaleRatio", "UpscaleRatioOverrideEnabled");
UpscaleRatioOverrideValue = readFloat("UpscaleRatio", "UpscaleRatioOverrideValue");

// View
Method = readViewMethod("View", "Method");
VerticalFOV = readFloat("View", "VerticalFOV");
NearPlane = readFloat("View", "NearPlane");
FarPlane = readFloat("View", "FarPlane");
}

auto exeName = Util::ExePath().filename();

if (exeName == "Cyberpunk2077.exe")
{
Method = Method.value_or(ViewMethod::Cyberpunk2077);
}
else if (exeName == "DyingLightGame_x64_rwdi.exe")
{
SharpnessRange = SharpnessRange.value_or(SharpnessRangeModifier::Extended);
}
else if (exeName == "RDR2.exe")
{
Method = Method.value_or(ViewMethod::RDR2);
}
}

std::optional<std::string> Config::readString(std::string section, std::string key, bool lowercase)
{
std::string value = ini.GetValue(section.c_str(), key.c_str(), "auto");

std::string lower = value;
std::transform(
lower.begin(), lower.end(),
lower.begin(),
[](unsigned char c)
{
return std::tolower(c);
}
);

if (lower == "auto")
{
return std::nullopt;
}
return lowercase ? lower : value;
}

std::optional<float> Config::readFloat(std::string section, std::string key)
{
auto value = readString(section, key);
try
{
return std::stof(value.value());
}
catch (const std::bad_optional_access&) // missing or auto value
{
return std::nullopt;
}
catch (const std::invalid_argument&) // invalid float string for std::stof
{
return std::nullopt;
}
catch (const std::out_of_range&) // out of range for 32 bit float
{
return std::nullopt;
}
}

std::optional<bool> Config::readBool(std::string section, std::string key)
{
auto value = readString(section, key, true);
if (value == "true")
{
return true;
}
else if (value == "false")
{
return false;
}

return std::nullopt;
}

std::optional<SharpnessRangeModifier> Config::readSharpnessRange(std::string section, std::string key)
{
auto value = readString(section, key, true);
if (value == "normal")
{
return SharpnessRangeModifier::Normal;
}
else if (value == "extended")
{
return SharpnessRangeModifier::Extended;
}

return std::nullopt;
}

std::optional<ViewMethod> Config::readViewMethod(std::string section, std::string key)
{
auto value = readString(section, key, true);
if (value == "config")
{
return ViewMethod::Config;
}
else if (value == "cyberpunk2077")
{
return ViewMethod::Cyberpunk2077;
}
else if (value == "rdr2")
{
return ViewMethod::RDR2;
}

return std::nullopt;
}
60 changes: 60 additions & 0 deletions CyberFSR/Config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once
#include "pch.h"

enum class SharpnessRangeModifier
{
Normal,
Extended,
};

enum class ViewMethod
{
Config,
Cyberpunk2077,
RDR2,
};

class Config
{
public:
Config(std::string fileName);

// Depth
std::optional<bool> DepthInverted;

// Color
std::optional<bool> AutoExposure;
std::optional<bool> HDR;

// Motion
std::optional<bool> JitterCancellation;
std::optional<bool> DisplayResolution;

// Sharpening
std::optional<bool> EnableSharpening;
std::optional<float> Sharpness;
std::optional<SharpnessRangeModifier> SharpnessRange;

// Upscale Ratio Override
std::optional<bool> UpscaleRatioOverrideEnabled;
std::optional<float> UpscaleRatioOverrideValue;

// View
std::optional<ViewMethod> Method;
std::optional<float> VerticalFOV;
std::optional<float> NearPlane;
std::optional<float> FarPlane;

void Reload();

private:
CSimpleIniA ini;

std::filesystem::path absoluteFileName;

std::optional<std::string> readString(std::string section, std::string key, bool lowercase = false);
std::optional<float> readFloat(std::string section, std::string key);
std::optional<bool> readBool(std::string section, std::string key);
std::optional<SharpnessRangeModifier> readSharpnessRange(std::string section, std::string key);
std::optional<ViewMethod> readViewMethod(std::string section, std::string key);
};
28 changes: 16 additions & 12 deletions CyberFSR/CyberFSR.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(SolutionDir)external\nvngx_dlss_sdk\include;$(SolutionDir)external\FidelityFX-FSR2\src;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)external\simpleini;$(SolutionDir)external\nvngx_dlss_sdk\include;$(SolutionDir)external\FidelityFX-FSR2\src;$(VULKAN_SDK)\Include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(SolutionDir)external\nvngx_dlss_sdk\include;$(SolutionDir)external\FidelityFX-FSR2\src;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)external\simpleini;$(SolutionDir)external\nvngx_dlss_sdk\include;$(SolutionDir)external\FidelityFX-FSR2\src;$(VULKAN_SDK)\Include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(SolutionDir)external\nvngx_dlss_sdk\include;$(SolutionDir)external\FidelityFX-FSR2\src;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)external\FidelityFX-FSR2\bin\ffx_fsr2_api;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)external\simpleini;$(SolutionDir)external\nvngx_dlss_sdk\include;$(SolutionDir)external\FidelityFX-FSR2\src;$(VULKAN_SDK)\Include;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)external\FidelityFX-FSR2\bin\ffx_fsr2_api;$(VULKAN_SDK)\Lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(SolutionDir)external\nvngx_dlss_sdk\include;$(SolutionDir)external\FidelityFX-FSR2\src;$(VULKAN_SDK)\Include;$(IncludePath)</IncludePath>
<LibraryPath>$(VULKAN_SDK)\Lib;$(SolutionDir)external\FidelityFX-FSR2\bin\ffx_fsr2_api;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)external\simpleini;$(SolutionDir)external\nvngx_dlss_sdk\include;$(SolutionDir)external\FidelityFX-FSR2\src;$(VULKAN_SDK)\Include;$(IncludePath)</IncludePath>
<TargetName>nvngx</TargetName>
<LibraryPath>$(SolutionDir)external\FidelityFX-FSR2\bin\ffx_fsr2_api;$(VULKAN_SDK)\Lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -136,7 +136,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>ffx_fsr2_api_x64d.lib;ffx_fsr2_api_dx12_x64d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>vulkan-1.lib;ffx_fsr2_api_x64d.lib;ffx_fsr2_api_dx12_x64d.lib;ffx_fsr2_api_vk_x64d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -161,22 +161,27 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>ffx_fsr2_api_dx12_x64.lib;ffx_fsr2_api_vk_x64.lib;ffx_fsr2_api_x64.lib;vulkan-1.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>vulkan-1.lib;ffx_fsr2_api_x64.lib;ffx_fsr2_api_dx12_x64.lib;ffx_fsr2_api_vk_x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Config.h" />
<ClInclude Include="CyberFsr.h" />
<ClInclude Include="Dx12ParameterImpl.h" />
<ClInclude Include="DirectXHooks.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="NvParameter.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Util.h" />
<ClInclude Include="ViewMatrixHook.h" />
<ClInclude Include="VkParameterImpl.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Config.cpp" />
<ClCompile Include="CyberFsr.cpp" />
<ClCompile Include="CyberFsrDx12.cpp" />
<ClCompile Include="CyberFsrVk.cpp" />
<ClCompile Include="DirectXHooks.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="Dx12ParameterImpl.cpp" />
<ClCompile Include="NvParameter.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
Expand All @@ -185,7 +190,6 @@
</ClCompile>
<ClCompile Include="Util.cpp" />
<ClCompile Include="ViewMatrixHook.cpp" />
<ClCompile Include="VkParameterImpl.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
24 changes: 18 additions & 6 deletions CyberFSR/CyberFSR.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@
<ClInclude Include="CyberFsr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Dx12ParameterImpl.h">
<ClInclude Include="Util.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Util.h">
<ClInclude Include="DirectXHooks.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ViewMatrixHook.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="VkParameterImpl.h">
<ClInclude Include="Config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="NvParameter.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
Expand All @@ -47,16 +50,25 @@
<ClCompile Include="CyberFsr.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Dx12ParameterImpl.cpp">
<ClCompile Include="Util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Util.cpp">
<ClCompile Include="DirectXHooks.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ViewMatrixHook.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="VkParameterImpl.cpp">
<ClCompile Include="Config.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CyberFsrVk.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CyberFsrDx12.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NvParameter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down
Loading

0 comments on commit a1a4d4d

Please sign in to comment.