Skip to content

Commit

Permalink
feat: allow disabling of upscaling/framegeneration
Browse files Browse the repository at this point in the history
Disable special features.

closes #606
  • Loading branch information
alandtse committed Oct 15, 2024
1 parent ccc0902 commit 39343d8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,18 +658,19 @@ namespace Hooks
void InstallD3DHooks()
{
auto streamline = Streamline::GetSingleton();
auto state = State::GetSingleton();

streamline->LoadInterposer();

if (streamline->interposer) {
if (streamline->interposer && !state->IsFeatureDisabled("Frame Generation")) {
Streamline::InstallHooks();

logger::info("Hooking D3D11CreateDeviceAndSwapChain");
*(uintptr_t*)&ptrD3D11CreateDeviceAndSwapChain = SKSE::PatchIAT(hk_D3D11CreateDeviceAndSwapChain, "d3d11.dll", "D3D11CreateDeviceAndSwapChain");

logger::info("Hooking CreateDXGIFactory");
*(uintptr_t*)&ptrCreateDXGIFactory = SKSE::PatchIAT(hk_CreateDXGIFactory, "dxgi.dll", !REL::Module::IsVR() ? "CreateDXGIFactory" : "CreateDXGIFactory1");
} else {
} else if (!state->IsFeatureDisabled("Upscaling")) {
logger::info("Hooking D3D11CreateDeviceAndSwapChain");
*(uintptr_t*)&ptrD3D11CreateDeviceAndSwapChain = SKSE::PatchIAT(hk_D3D11CreateDeviceAndSwapChainNoStreamline, "d3d11.dll", "D3D11CreateDeviceAndSwapChain");
}
Expand Down
34 changes: 29 additions & 5 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,11 +828,35 @@ void Menu::DrawDisableAtBootSettings()

void Menu::DrawDisplaySettings()
{
if (ImGui::CollapsingHeader("Upscaling", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) {
Upscaling::GetSingleton()->DrawSettings();
}
if (!REL::Module::IsVR() && ImGui::CollapsingHeader("Frame Generation", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) {
Streamline::GetSingleton()->DrawSettings();
auto& themeSettings = Menu::GetSingleton()->settings.Theme;

const std::vector<std::pair<std::string, std::function<void()>>> features = {
{ "Upscaling", []() { Upscaling::GetSingleton()->DrawSettings(); } },
{ "Frame Generation", []() { Streamline::GetSingleton()->DrawSettings(); } }
};

for (const auto& [featureName, drawFunc] : features) {
bool isDisabled = State::GetSingleton()->IsFeatureDisabled(featureName);

if (featureName == "Frame Generation" && REL::Module::IsVR()) {
isDisabled = true;
}

if (!isDisabled) {
if (ImGui::CollapsingHeader(featureName.c_str(), ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) {
drawFunc();
}
} else {
ImGui::PushStyleColor(ImGuiCol_Text, themeSettings.DisableColor);
ImGui::CollapsingHeader(featureName.c_str(), ImGuiTreeNodeFlags_NoTreePushOnOpen);
ImGui::PopStyleColor();
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"%s has been disabled at boot. "
"Reenable in the Advanced -> Disable at Boot Menu.",
featureName.c_str());
}
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ void State::Load(ConfigMode a_configMode)
logger::warn("Invalid entry for feature '{}' in 'Disable at Boot', expected boolean.", featureName);
}
}
for (const auto& [featureName, _] : specialFeatures) {
if (IsFeatureDisabled(featureName)) {
logger::info("Special Feature '{}' disabled at boot", featureName);
}
}

auto truePBR = TruePBR::GetSingleton();
auto& pbrJson = settings[truePBR->GetShortName()];
Expand Down
4 changes: 4 additions & 0 deletions src/Streamline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ void Streamline::DrawSettings()

void Streamline::LoadInterposer()
{
if (State::GetSingleton()->IsFeatureDisabled("Frame Generation")) {
return;
}

interposer = LoadLibraryW(L"Data/SKSE/Plugins/Streamline/sl.interposer.dll");
if (interposer == nullptr) {
DWORD errorCode = GetLastError();
Expand Down
4 changes: 3 additions & 1 deletion src/XSEPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ void MessageHandler(SKSE::MessagingInterface::Message* message)
state->PostPostLoad(); // state should load first so basic information is populated
Deferred::Hooks::Install();
TruePBR::GetSingleton()->PostPostLoad();
Upscaling::InstallHooks();
if (!state->IsFeatureDisabled("Upscaling")) {
Upscaling::InstallHooks();
}
Hooks::Install();
FrameAnnotations::OnPostPostLoad();

Expand Down

0 comments on commit 39343d8

Please sign in to comment.