mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-11-16 10:46:45 +00:00
1237 lines
39 KiB
C++
1237 lines
39 KiB
C++
#include "Streamline_Hooks.h"
|
|
|
|
#include <json.hpp>
|
|
#include "detours/detours.h"
|
|
|
|
#include <Util.h>
|
|
#include <Config.h>
|
|
#include <proxies/KernelBase_Proxy.h>
|
|
#include <menu/menu_overlay_base.h>
|
|
#include <nvapi/ReflexHooks.h>
|
|
#include <magic_enum.hpp>
|
|
#include <sl1_reflex.h>
|
|
#include <nvapi/fakenvapi.h>
|
|
|
|
sl::RenderAPI StreamlineHooks::renderApi = sl::RenderAPI::eCount;
|
|
std::mutex StreamlineHooks::setConstantsMutex {};
|
|
SystemCaps* StreamlineHooks::systemCaps = nullptr;
|
|
SystemCapsSl15* StreamlineHooks::systemCapsSl15 = nullptr;
|
|
|
|
// interposer
|
|
decltype(&slInit) StreamlineHooks::o_slInit = nullptr;
|
|
decltype(&slSetTag) StreamlineHooks::o_slSetTag = nullptr;
|
|
decltype(&slSetTagForFrame) StreamlineHooks::o_slSetTagForFrame = nullptr;
|
|
decltype(&slEvaluateFeature) StreamlineHooks::o_slEvaluateFeature = nullptr;
|
|
decltype(&slAllocateResources) StreamlineHooks::o_slAllocateResources = nullptr;
|
|
decltype(&slSetConstants) StreamlineHooks::o_slSetConstants = nullptr;
|
|
decltype(&slGetNativeInterface) StreamlineHooks::o_slGetNativeInterface = nullptr;
|
|
decltype(&slSetD3DDevice) StreamlineHooks::o_slSetD3DDevice = nullptr;
|
|
decltype(&slGetNewFrameToken) StreamlineHooks::o_slGetNewFrameToken = nullptr;
|
|
|
|
decltype(&sl1::slInit) StreamlineHooks::o_slInit_sl1 = nullptr;
|
|
|
|
sl::PFun_LogMessageCallback* StreamlineHooks::o_logCallback = nullptr;
|
|
sl1::pfunLogMessageCallback* StreamlineHooks::o_logCallback_sl1 = nullptr;
|
|
|
|
// DLSS
|
|
StreamlineHooks::PFN_slGetPluginFunction StreamlineHooks::o_dlss_slGetPluginFunction = nullptr;
|
|
StreamlineHooks::PFN_slOnPluginLoad StreamlineHooks::o_dlss_slOnPluginLoad = nullptr;
|
|
|
|
// DLSSG
|
|
StreamlineHooks::PFN_slGetPluginFunction StreamlineHooks::o_dlssg_slGetPluginFunction = nullptr;
|
|
StreamlineHooks::PFN_slOnPluginLoad StreamlineHooks::o_dlssg_slOnPluginLoad = nullptr;
|
|
decltype(&slDLSSGSetOptions) StreamlineHooks::o_slDLSSGSetOptions = nullptr;
|
|
|
|
// Reflex
|
|
StreamlineHooks::PFN_slGetPluginFunction StreamlineHooks::o_reflex_slGetPluginFunction = nullptr;
|
|
StreamlineHooks::PFN_slSetConstants_sl1 StreamlineHooks::o_reflex_slSetConstants_sl1 = nullptr;
|
|
StreamlineHooks::PFN_slOnPluginLoad StreamlineHooks::o_reflex_slOnPluginLoad = nullptr;
|
|
decltype(&slReflexSetOptions) StreamlineHooks::o_slReflexSetOptions = nullptr;
|
|
sl::ReflexMode StreamlineHooks::reflexGamesLastMode = sl::ReflexMode::eOff;
|
|
|
|
// PCL
|
|
StreamlineHooks::PFN_slGetPluginFunction StreamlineHooks::o_pcl_slGetPluginFunction = nullptr;
|
|
StreamlineHooks::PFN_slOnPluginLoad StreamlineHooks::o_pcl_slOnPluginLoad = nullptr;
|
|
decltype(&slPCLSetMarker) StreamlineHooks::o_slPCLSetMarker = nullptr;
|
|
|
|
// Common
|
|
StreamlineHooks::PFN_slGetPluginFunction StreamlineHooks::o_common_slGetPluginFunction = nullptr;
|
|
StreamlineHooks::PFN_slOnPluginLoad StreamlineHooks::o_common_slOnPluginLoad = nullptr;
|
|
StreamlineHooks::PFN_slSetParameters_sl1 StreamlineHooks::o_common_slSetParameters_sl1 = nullptr;
|
|
StreamlineHooks::PFN_setVoid StreamlineHooks::o_setVoid = nullptr;
|
|
|
|
char* StreamlineHooks::trimStreamlineLog(const char* msg)
|
|
{
|
|
int bracket_count = 0;
|
|
|
|
char* result = (char*) malloc(strlen(msg) + 1);
|
|
if (!result)
|
|
return nullptr;
|
|
|
|
strcpy(result, msg);
|
|
|
|
size_t length = strlen(result);
|
|
if (length > 0 && result[length - 1] == '\n')
|
|
{
|
|
result[length - 1] = '\0';
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void StreamlineHooks::streamlineLogCallback(sl::LogType type, const char* msg)
|
|
{
|
|
if (msg == nullptr)
|
|
return;
|
|
|
|
char* trimmed_msg = trimStreamlineLog(msg);
|
|
if (trimmed_msg != nullptr)
|
|
{
|
|
switch (type)
|
|
{
|
|
case sl::LogType::eWarn:
|
|
LOG_WARN("{}", trimmed_msg);
|
|
break;
|
|
case sl::LogType::eInfo:
|
|
LOG_INFO("{}", trimmed_msg);
|
|
break;
|
|
case sl::LogType::eError:
|
|
LOG_ERROR("{}", trimmed_msg);
|
|
break;
|
|
case sl::LogType::eCount:
|
|
LOG_ERROR("{}", trimmed_msg);
|
|
break;
|
|
}
|
|
|
|
free(trimmed_msg);
|
|
}
|
|
|
|
if (o_logCallback != nullptr)
|
|
o_logCallback(type, msg);
|
|
}
|
|
|
|
sl::Result StreamlineHooks::hkslInit(sl::Preferences* pref, uint64_t sdkVersion)
|
|
{
|
|
LOG_FUNC();
|
|
if (pref->logMessageCallback != &streamlineLogCallback)
|
|
o_logCallback = pref->logMessageCallback;
|
|
pref->logLevel = sl::LogLevel::eCount;
|
|
pref->logMessageCallback = &streamlineLogCallback;
|
|
|
|
// renderAPI is optional so need to be careful, should only matter for Vulkan
|
|
renderApi = pref->renderAPI;
|
|
|
|
State::Instance().slFGInputs.reportEngineType(pref->engine);
|
|
|
|
// Treat engine type set in Streamline as ground truth
|
|
if (pref->engine == sl::EngineType::eUnreal)
|
|
State::Instance().gameQuirks |= GameQuirk::ForceUnrealEngine;
|
|
|
|
// bool hookSetTag =
|
|
// (State::Instance().activeFgInput == FGInput::Nukems || State::Instance().activeFgInput == FGInput::DLSSG);
|
|
|
|
// if (hookSetTag)
|
|
// pref->flags &= ~(sl::PreferenceFlags::eAllowOTA | sl::PreferenceFlags::eLoadDownloadedPlugins);
|
|
|
|
return o_slInit(*pref, sdkVersion);
|
|
}
|
|
|
|
sl::Result StreamlineHooks::hkslSetTag(sl::ViewportHandle& viewport, sl::ResourceTag* tags, uint32_t numTags,
|
|
sl::CommandBuffer* cmdBuffer)
|
|
{
|
|
if (renderApi == sl::RenderAPI::eD3D11 || renderApi == sl::RenderAPI::eVulkan)
|
|
{
|
|
LOG_ERROR("hkslSetTag only supports DX12");
|
|
return o_slSetTag(viewport, tags, numTags, cmdBuffer);
|
|
}
|
|
|
|
if (renderApi == sl::RenderAPI::eCount)
|
|
LOG_WARN("Incomplete Streamline hooks");
|
|
|
|
if (tags == nullptr)
|
|
{
|
|
LOG_WARN("Game trying to remove a tag");
|
|
return o_slSetTag(viewport, tags, numTags, cmdBuffer);
|
|
}
|
|
|
|
for (uint32_t i = 0; i < numTags; i++)
|
|
{
|
|
if (tags[i].resource == nullptr || tags[i].resource->native == nullptr)
|
|
{
|
|
LOG_TRACE("Resource of type: {} is null, continuing", tags[i].type);
|
|
continue;
|
|
}
|
|
|
|
// Cyberpunk hudless state fix for RDNA 2
|
|
if (State::Instance().gameQuirks & GameQuirk::CyberpunkHudlessStateOverride &&
|
|
tags[i].resource->state ==
|
|
(D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE) &&
|
|
tags[i].type == sl::kBufferTypeHUDLessColor)
|
|
{
|
|
tags[i].resource->state = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
|
|
LOG_TRACE("Changing hudless resource state");
|
|
}
|
|
|
|
if (State::Instance().activeFgInput == FGInput::DLSSG &&
|
|
(tags[i].type == sl::kBufferTypeHUDLessColor || tags[i].type == sl::kBufferTypeDepth ||
|
|
tags[i].type == sl::kBufferTypeHiResDepth || tags[i].type == sl::kBufferTypeLinearDepth ||
|
|
tags[i].type == sl::kBufferTypeMotionVectors || tags[i].type == sl::kBufferTypeUIColorAndAlpha ||
|
|
tags[i].type == sl::kBufferTypeBidirectionalDistortionField))
|
|
{
|
|
State::Instance().slFGInputs.reportResource(tags[i], (ID3D12GraphicsCommandList*) cmdBuffer, 0);
|
|
}
|
|
}
|
|
|
|
auto result = o_slSetTag(viewport, tags, numTags, cmdBuffer);
|
|
return result;
|
|
}
|
|
|
|
sl::Result StreamlineHooks::hkslSetTagForFrame(const sl::FrameToken& frame, const sl::ViewportHandle& viewport,
|
|
const sl::ResourceTag* resources, uint32_t numResources,
|
|
sl::CommandBuffer* cmdBuffer)
|
|
{
|
|
if (renderApi == sl::RenderAPI::eD3D11 || renderApi == sl::RenderAPI::eVulkan)
|
|
{
|
|
LOG_ERROR("hkslSetTagForFrame only supports DX12");
|
|
return o_slSetTagForFrame(frame, viewport, resources, numResources, cmdBuffer);
|
|
}
|
|
|
|
if (renderApi == sl::RenderAPI::eCount)
|
|
LOG_WARN("Incomplete Streamline hooks");
|
|
|
|
if (resources == nullptr)
|
|
{
|
|
LOG_WARN("Game trying to remove a tag");
|
|
return o_slSetTagForFrame(frame, viewport, resources, numResources, cmdBuffer);
|
|
}
|
|
|
|
for (uint32_t i = 0; i < numResources; i++)
|
|
{
|
|
if (resources[i].resource == nullptr)
|
|
{
|
|
LOG_TRACE("Resource of type: {} is null, continuing", resources[i].type);
|
|
continue;
|
|
}
|
|
|
|
if (State::Instance().activeFgInput == FGInput::DLSSG &&
|
|
(resources[i].type == sl::kBufferTypeHUDLessColor || resources[i].type == sl::kBufferTypeDepth ||
|
|
resources[i].type == sl::kBufferTypeHiResDepth || resources[i].type == sl::kBufferTypeLinearDepth ||
|
|
resources[i].type == sl::kBufferTypeMotionVectors || resources[i].type == sl::kBufferTypeUIColorAndAlpha ||
|
|
resources[i].type == sl::kBufferTypeBidirectionalDistortionField))
|
|
{
|
|
State::Instance().slFGInputs.reportResource(resources[i], (ID3D12GraphicsCommandList*) cmdBuffer,
|
|
(uint32_t) frame);
|
|
}
|
|
}
|
|
|
|
auto result = o_slSetTagForFrame(frame, viewport, resources, numResources, cmdBuffer);
|
|
return result;
|
|
}
|
|
|
|
sl::Result StreamlineHooks::hkslEvaluateFeature(sl::Feature feature, const sl::FrameToken& frame,
|
|
const sl::BaseStructure** inputs, uint32_t numInputs,
|
|
sl::CommandBuffer* cmdBuffer)
|
|
{
|
|
LOG_FUNC();
|
|
auto result = o_slEvaluateFeature(feature, frame, inputs, numInputs, cmdBuffer);
|
|
return result;
|
|
}
|
|
|
|
sl::Result StreamlineHooks::hkslAllocateResources(sl::CommandBuffer* cmdBuffer, sl::Feature feature,
|
|
const sl::ViewportHandle& viewport)
|
|
{
|
|
LOG_FUNC();
|
|
auto result = o_slAllocateResources(cmdBuffer, feature, viewport);
|
|
return result;
|
|
}
|
|
|
|
sl::Result StreamlineHooks::hkslGetNativeInterface(void* proxyInterface, void** baseInterface)
|
|
{
|
|
LOG_FUNC();
|
|
auto result = o_slGetNativeInterface(proxyInterface, baseInterface);
|
|
return result;
|
|
}
|
|
|
|
sl::Result StreamlineHooks::hkslSetD3DDevice(void* d3dDevice)
|
|
{
|
|
LOG_FUNC();
|
|
auto result = o_slSetD3DDevice(d3dDevice);
|
|
return result;
|
|
}
|
|
|
|
void StreamlineHooks::streamlineLogCallback_sl1(sl1::LogType type, const char* msg)
|
|
{
|
|
char* trimmed_msg = trimStreamlineLog(msg);
|
|
|
|
switch (type)
|
|
{
|
|
case sl1::LogType::eLogTypeWarn:
|
|
LOG_WARN("{}", trimmed_msg);
|
|
break;
|
|
case sl1::LogType::eLogTypeInfo:
|
|
LOG_INFO("{}", trimmed_msg);
|
|
break;
|
|
case sl1::LogType::eLogTypeError:
|
|
LOG_ERROR("{}", trimmed_msg);
|
|
break;
|
|
case sl1::LogType::eLogTypeCount:
|
|
LOG_ERROR("{}", trimmed_msg);
|
|
break;
|
|
}
|
|
|
|
free(trimmed_msg);
|
|
|
|
if (o_logCallback_sl1)
|
|
o_logCallback_sl1(type, msg);
|
|
}
|
|
|
|
bool StreamlineHooks::hkslInit_sl1(sl1::Preferences* pref, int applicationId)
|
|
{
|
|
LOG_FUNC();
|
|
if (pref->logMessageCallback != &streamlineLogCallback_sl1)
|
|
o_logCallback_sl1 = pref->logMessageCallback;
|
|
pref->logLevel = sl1::LogLevel::eLogLevelCount;
|
|
pref->logMessageCallback = &streamlineLogCallback_sl1;
|
|
return o_slInit_sl1(*pref, applicationId);
|
|
}
|
|
|
|
void StreamlineHooks::hookSystemCaps(sl::param::IParameters* params)
|
|
{
|
|
if (State::Instance().streamlineVersion.major > 1)
|
|
{
|
|
if (!systemCaps)
|
|
sl::param::getPointerParam(params, sl::param::common::kSystemCaps, &systemCaps);
|
|
}
|
|
else if (State::Instance().streamlineVersion.major == 1)
|
|
{
|
|
// This should be Streamline 1.5 as previous versions don't even have slOnPluginLoad
|
|
if (!systemCapsSl15)
|
|
{
|
|
LOG_TRACE(
|
|
"Attempting to get system caps for Streamline v1, this could fail depending on the exact version");
|
|
sl::param::getPointerParam(params, sl::param::common::kSystemCaps, &systemCapsSl15);
|
|
}
|
|
}
|
|
}
|
|
|
|
uint32_t StreamlineHooks::getSystemCapsArch()
|
|
{
|
|
uint32_t highestArch = 0;
|
|
|
|
if (!fakenvapi::isUsingFakenvapi() && State::Instance().isRunningOnNvidia)
|
|
{
|
|
if (State::Instance().streamlineVersion.major > 1)
|
|
{
|
|
if (systemCaps)
|
|
{
|
|
for (auto& adapter : systemCaps->adapters)
|
|
{
|
|
if (adapter.architecture > highestArch)
|
|
highestArch = adapter.architecture;
|
|
}
|
|
}
|
|
}
|
|
else if (State::Instance().streamlineVersion.major == 1)
|
|
{
|
|
if (systemCapsSl15)
|
|
{
|
|
for (uint32_t i = 0; i < systemCapsSl15->gpuCount; i++)
|
|
{
|
|
if (systemCapsSl15->architecture[i] > highestArch)
|
|
highestArch = systemCapsSl15->architecture[i];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// By default spoof Pascal, gets Reflex but not DLSSD
|
|
// Could be problematic if not using fakenvapi but nvapi might not be initialized yet
|
|
if (highestArch == 0)
|
|
highestArch = NV_GPU_ARCHITECTURE_GP100;
|
|
|
|
return highestArch;
|
|
}
|
|
|
|
void StreamlineHooks::setArch(uint32_t arch)
|
|
{
|
|
if (State::Instance().streamlineVersion.major > 1)
|
|
{
|
|
if (systemCaps)
|
|
{
|
|
for (uint32_t i = 0; i < systemCaps->gpuCount; i++)
|
|
{
|
|
systemCaps->adapters[i].architecture = arch;
|
|
systemCaps->adapters[i].vendor = VendorId::Nvidia;
|
|
}
|
|
|
|
if (fakenvapi::isUsingFakenvapi() || !State::Instance().isRunningOnNvidia)
|
|
systemCaps->driverVersionMajor = 999;
|
|
|
|
systemCaps->hwsSupported = true;
|
|
}
|
|
}
|
|
else if (State::Instance().streamlineVersion.major == 1)
|
|
{
|
|
if (systemCapsSl15)
|
|
{
|
|
for (uint32_t i = 0; i < systemCapsSl15->gpuCount; i++)
|
|
systemCapsSl15->architecture[i] = arch;
|
|
|
|
if (fakenvapi::isUsingFakenvapi() || !State::Instance().isRunningOnNvidia)
|
|
systemCapsSl15->driverVersionMajor = 999;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Spoof arch based on feature and current arch
|
|
void StreamlineHooks::spoofArch(uint32_t currentArch, sl::Feature feature)
|
|
{
|
|
constexpr uint32_t maxArch = 0xFFFFFFFF;
|
|
|
|
// Don't change arch for DLSS/DLSSD with turing and above
|
|
if (feature == sl::kFeatureDLSS)
|
|
{
|
|
if (currentArch < NV_GPU_ARCHITECTURE_TU100)
|
|
return setArch(maxArch);
|
|
}
|
|
|
|
// Don't spoof DLSSD at all
|
|
else if (feature == sl::kFeatureDLSS_RR)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Don't change arch for DLSSG with ada and above
|
|
else if (feature == sl::kFeatureDLSS_G)
|
|
{
|
|
if (currentArch < NV_GPU_ARCHITECTURE_AD100)
|
|
return setArch(maxArch);
|
|
}
|
|
|
|
else if (feature == sl::kFeatureReflex || feature == sl::kFeaturePCL)
|
|
{
|
|
if (fakenvapi::isUsingFakenvapi())
|
|
return setArch(maxArch);
|
|
}
|
|
}
|
|
|
|
bool StreamlineHooks::hkdlss_slOnPluginLoad(void* params, const char* loaderJSON, const char** pluginJSON)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
// TODO: do it better than "static" and hoping for the best
|
|
static std::string config;
|
|
|
|
uint32_t currentArch = 0;
|
|
if (Config::Instance()->StreamlineSpoofing.value_or_default())
|
|
{
|
|
hookSystemCaps((sl::param::IParameters*) params);
|
|
currentArch = getSystemCapsArch();
|
|
spoofArch(currentArch, sl::kFeatureDLSS);
|
|
}
|
|
|
|
auto result = o_dlss_slOnPluginLoad(params, loaderJSON, pluginJSON);
|
|
|
|
if (Config::Instance()->StreamlineSpoofing.value_or_default())
|
|
setArch(currentArch);
|
|
|
|
if (Config::Instance()->VulkanExtensionSpoofing.value_or_default())
|
|
{
|
|
nlohmann::json configJson = nlohmann::json::parse(*pluginJSON);
|
|
|
|
configJson["external"]["vk"]["instance"]["extensions"].clear();
|
|
configJson["external"]["vk"]["device"]["extensions"].clear();
|
|
configJson["external"]["vk"]["device"]["1.2_features"].clear();
|
|
|
|
config = configJson.dump();
|
|
|
|
*pluginJSON = config.c_str();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
bool StreamlineHooks::hkdlssg_slOnPluginLoad(void* params, const char* loaderJSON, const char** pluginJSON)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
// TODO: do it better than "static" and hoping for the best
|
|
static std::string config;
|
|
|
|
bool shouldSpoofArch =
|
|
Config::Instance()->StreamlineSpoofing.value_or_default() &&
|
|
(Config::Instance()->FGInput == FGInput::Nukems || Config::Instance()->FGInput == FGInput::DLSSG);
|
|
|
|
uint32_t currentArch = 0;
|
|
if (shouldSpoofArch)
|
|
{
|
|
hookSystemCaps((sl::param::IParameters*) params);
|
|
currentArch = getSystemCapsArch();
|
|
spoofArch(currentArch, sl::kFeatureDLSS_G);
|
|
}
|
|
|
|
auto result = o_dlssg_slOnPluginLoad(params, loaderJSON, pluginJSON);
|
|
|
|
if (shouldSpoofArch)
|
|
setArch(currentArch);
|
|
|
|
nlohmann::json configJson = nlohmann::json::parse(*pluginJSON);
|
|
|
|
// Kill the DLSSG streamline swapchain hooks
|
|
if (State::Instance().activeFgInput == FGInput::DLSSG)
|
|
{
|
|
configJson["hooks"].clear();
|
|
configJson["exclusive_hooks"].clear();
|
|
configJson["external"]["feature"]["tags"].clear(); // We handle the DLSSG resources
|
|
}
|
|
|
|
if (Config::Instance()->VulkanExtensionSpoofing.value_or_default())
|
|
{
|
|
configJson["external"]["vk"]["instance"]["extensions"].clear();
|
|
configJson["external"]["vk"]["device"]["extensions"].clear();
|
|
configJson["external"]["vk"]["device"]["1.2_features"].clear();
|
|
}
|
|
|
|
config = configJson.dump();
|
|
|
|
*pluginJSON = config.c_str();
|
|
|
|
return result;
|
|
}
|
|
|
|
sl::Result StreamlineHooks::hkslSetConstants(const sl::Constants& values, const sl::FrameToken& frame,
|
|
const sl::ViewportHandle& viewport)
|
|
{
|
|
std::scoped_lock lock(setConstantsMutex);
|
|
LOG_TRACE("called with frameIndex: {}, viewport: {}", (unsigned int) frame, (unsigned int) viewport);
|
|
|
|
State::Instance().slFGInputs.setConstants(values, (uint32_t) frame);
|
|
|
|
return o_slSetConstants(values, frame, viewport);
|
|
}
|
|
|
|
bool StreamlineHooks::hkcommon_slOnPluginLoad(void* params, const char* loaderJSON, const char** pluginJSON)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
// TODO: do it better than "static" and hoping for the best
|
|
static std::string config;
|
|
|
|
auto result = o_common_slOnPluginLoad(params, loaderJSON, pluginJSON);
|
|
|
|
// Completely disables Streamline hooks
|
|
// if (true)
|
|
//{
|
|
// nlohmann::json configJson = nlohmann::json::parse(*pluginJSON);
|
|
|
|
// configJson["hooks"].clear();
|
|
// configJson["exclusive_hooks"].clear();
|
|
|
|
// config = configJson.dump();
|
|
|
|
// *pluginJSON = config.c_str();
|
|
//}
|
|
|
|
return result;
|
|
}
|
|
|
|
sl::Result StreamlineHooks::hkslDLSSGSetOptions(const sl::ViewportHandle& viewport, const sl::DLSSGOptions& options)
|
|
{
|
|
// Make DLSSG auto always mean On
|
|
sl::DLSSGOptions newOptions = options;
|
|
newOptions.mode = newOptions.mode == sl::DLSSGMode::eOff ? sl::DLSSGMode::eOff : sl::DLSSGMode::eOn;
|
|
|
|
if (State::Instance().api == API::Vulkan)
|
|
{
|
|
// Only matters for Vulkan, DX doesn't use this delay
|
|
if (options.mode != sl::DLSSGMode::eOff && !MenuOverlayBase::IsVisible())
|
|
State::Instance().delayMenuRenderBy = 10;
|
|
|
|
if (MenuOverlayBase::IsVisible())
|
|
{
|
|
newOptions.mode = sl::DLSSGMode::eOff;
|
|
newOptions.flags |= sl::DLSSGFlags::eRetainResourcesWhenOff;
|
|
ReflexHooks::setDlssgDetectedState(false);
|
|
}
|
|
}
|
|
|
|
LOG_TRACE("DLSSG Modified Mode: {}", magic_enum::enum_name(newOptions.mode));
|
|
|
|
return o_slDLSSGSetOptions(viewport, newOptions);
|
|
}
|
|
|
|
bool StreamlineHooks::hkreflex_slOnPluginLoad(void* params, const char* loaderJSON, const char** pluginJSON)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
uint32_t currentArch = 0;
|
|
if (Config::Instance()->StreamlineSpoofing.value_or_default())
|
|
{
|
|
hookSystemCaps((sl::param::IParameters*) params);
|
|
currentArch = getSystemCapsArch();
|
|
spoofArch(currentArch, sl::kFeatureReflex);
|
|
}
|
|
|
|
auto result = o_reflex_slOnPluginLoad(params, loaderJSON, pluginJSON);
|
|
|
|
if (Config::Instance()->StreamlineSpoofing.value_or_default())
|
|
setArch(currentArch);
|
|
|
|
return result;
|
|
}
|
|
|
|
sl::Result StreamlineHooks::hkslReflexSetOptions(const sl::ReflexOptions& options)
|
|
{
|
|
reflexGamesLastMode = options.mode;
|
|
|
|
sl::ReflexOptions newOptions = options;
|
|
|
|
if (Config::Instance()->FN_ForceReflex == 2)
|
|
newOptions.mode = sl::ReflexMode::eLowLatencyWithBoost;
|
|
|
|
// Will cause a pink screen when used with DLSSG
|
|
// if (Config::Instance()->FN_ForceReflex == 1)
|
|
// newOptions.mode = sl::ReflexMode::eOff;
|
|
|
|
return o_slReflexSetOptions(newOptions);
|
|
}
|
|
|
|
void* StreamlineHooks::hkdlss_slGetPluginFunction(const char* functionName)
|
|
{
|
|
// LOG_DEBUG("{}", functionName);
|
|
|
|
if (strcmp(functionName, "slOnPluginLoad") == 0)
|
|
{
|
|
o_dlss_slOnPluginLoad = (PFN_slOnPluginLoad) o_dlss_slGetPluginFunction(functionName);
|
|
return &hkdlss_slOnPluginLoad;
|
|
}
|
|
|
|
return o_dlss_slGetPluginFunction(functionName);
|
|
}
|
|
|
|
void* StreamlineHooks::hkdlssg_slGetPluginFunction(const char* functionName)
|
|
{
|
|
// LOG_DEBUG("{}", functionName);
|
|
|
|
if (strcmp(functionName, "slOnPluginLoad") == 0)
|
|
{
|
|
o_dlssg_slOnPluginLoad = (PFN_slOnPluginLoad) o_dlssg_slGetPluginFunction(functionName);
|
|
return &hkdlssg_slOnPluginLoad;
|
|
}
|
|
|
|
if (strcmp(functionName, "slDLSSGSetOptions") == 0)
|
|
{
|
|
// Give steam overlay the original as it seems to be hooking it
|
|
auto steamOverlay = KernelBaseProxy::GetModuleHandleA_()("gameoverlayrenderer64.dll");
|
|
if (steamOverlay != nullptr)
|
|
{
|
|
if (HMODULE callerModule = Util::GetCallerModule(_ReturnAddress()); callerModule == steamOverlay)
|
|
{
|
|
return o_dlssg_slGetPluginFunction(functionName);
|
|
}
|
|
}
|
|
|
|
o_slDLSSGSetOptions = (decltype(&slDLSSGSetOptions)) o_dlssg_slGetPluginFunction(functionName);
|
|
return &hkslDLSSGSetOptions;
|
|
}
|
|
|
|
return o_dlssg_slGetPluginFunction(functionName);
|
|
}
|
|
|
|
bool StreamlineHooks::hkreflex_slSetConstants_sl1(const void* data, uint32_t frameIndex, uint32_t id)
|
|
{
|
|
// Streamline v1's version of slReflexSetOptions + slPCLSetMarker
|
|
static sl1::ReflexConstants constants {};
|
|
constants = *(const sl1::ReflexConstants*) data;
|
|
|
|
reflexGamesLastMode = (sl::ReflexMode) constants.mode;
|
|
|
|
LOG_DEBUG("mode: {}, frameIndex: {}, id: {}", (uint32_t) constants.mode, frameIndex, id);
|
|
|
|
if (Config::Instance()->FN_ForceReflex == 2)
|
|
constants.mode = sl1::ReflexMode::eReflexModeLowLatencyWithBoost;
|
|
|
|
// Will cause a pink screen when used with DLSSG
|
|
// else if (Config::Instance()->FN_ForceReflex == 1)
|
|
// constants.mode = sl1::ReflexMode::eReflexModeOff;
|
|
|
|
return o_reflex_slSetConstants_sl1(&constants, frameIndex, id);
|
|
}
|
|
|
|
void* StreamlineHooks::hkreflex_slGetPluginFunction(const char* functionName)
|
|
{
|
|
// LOG_DEBUG("{}", functionName);
|
|
|
|
if (strcmp(functionName, "slSetConstants") == 0 && State::Instance().streamlineVersion.major == 1)
|
|
{
|
|
o_reflex_slSetConstants_sl1 = (PFN_slSetConstants_sl1) o_reflex_slGetPluginFunction(functionName);
|
|
return &hkreflex_slSetConstants_sl1;
|
|
}
|
|
|
|
if (strcmp(functionName, "slOnPluginLoad") == 0)
|
|
{
|
|
o_reflex_slOnPluginLoad = (PFN_slOnPluginLoad) o_reflex_slGetPluginFunction(functionName);
|
|
return &hkreflex_slOnPluginLoad;
|
|
}
|
|
|
|
if (strcmp(functionName, "slReflexSetOptions") == 0)
|
|
{
|
|
o_slReflexSetOptions = (decltype(&slReflexSetOptions)) o_reflex_slGetPluginFunction(functionName);
|
|
return &hkslReflexSetOptions;
|
|
}
|
|
|
|
return o_reflex_slGetPluginFunction(functionName);
|
|
}
|
|
|
|
sl::Result StreamlineHooks::hkslPCLSetMarker(sl::PCLMarker marker, const sl::FrameToken& frame)
|
|
{
|
|
// HACK for broken games
|
|
static uint64_t last_simulation_end_id = 0;
|
|
if (marker == sl::PCLMarker::eSimulationEnd)
|
|
{
|
|
last_simulation_end_id = frame;
|
|
}
|
|
|
|
if (marker == sl::PCLMarker::eSimulationStart && last_simulation_end_id >= frame && o_slGetNewFrameToken)
|
|
{
|
|
const uint64_t correction_offset = last_simulation_end_id - frame + 1;
|
|
uint32_t newFrameId = frame + correction_offset;
|
|
|
|
sl::FrameToken* newFramePointer {};
|
|
auto result = o_slGetNewFrameToken(newFramePointer, &newFrameId);
|
|
|
|
LOG_WARN("Simulation start marker sent after end marker, offset: {}", correction_offset);
|
|
|
|
result = o_slPCLSetMarker(marker, *newFramePointer);
|
|
return result;
|
|
}
|
|
|
|
return o_slPCLSetMarker(marker, frame);
|
|
}
|
|
|
|
bool StreamlineHooks::hkpcl_slOnPluginLoad(void* params, const char* loaderJSON, const char** pluginJSON)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
uint32_t currentArch = 0;
|
|
if (Config::Instance()->StreamlineSpoofing.value_or_default())
|
|
{
|
|
hookSystemCaps((sl::param::IParameters*) params);
|
|
currentArch = getSystemCapsArch();
|
|
spoofArch(currentArch, sl::kFeaturePCL);
|
|
}
|
|
|
|
auto result = o_pcl_slOnPluginLoad(params, loaderJSON, pluginJSON);
|
|
|
|
if (Config::Instance()->StreamlineSpoofing.value_or_default())
|
|
setArch(currentArch);
|
|
|
|
return result;
|
|
}
|
|
|
|
void* StreamlineHooks::hkpcl_slGetPluginFunction(const char* functionName)
|
|
{
|
|
// LOG_DEBUG("{}", functionName);
|
|
|
|
if (strcmp(functionName, "slPCLSetMarker") == 0 && State::Instance().gameQuirks & GameQuirk::FixSlSimulationMarkers)
|
|
{
|
|
o_slPCLSetMarker = (decltype(&slPCLSetMarker)) o_pcl_slGetPluginFunction(functionName);
|
|
return &hkslPCLSetMarker;
|
|
}
|
|
|
|
if (strcmp(functionName, "slOnPluginLoad") == 0)
|
|
{
|
|
o_pcl_slOnPluginLoad = (PFN_slOnPluginLoad) o_pcl_slGetPluginFunction(functionName);
|
|
return &hkpcl_slOnPluginLoad;
|
|
}
|
|
|
|
return o_pcl_slGetPluginFunction(functionName);
|
|
}
|
|
|
|
bool StreamlineHooks::hk_setVoid(void* self, const char* key, void** value)
|
|
{
|
|
// LOG_DEBUG("{}", key);
|
|
|
|
if (strcmp(key, sl::param::common::kSystemCaps) == 0)
|
|
{
|
|
LOG_TRACE("Attempting to change system caps for Streamline v1, this could fail depending on the exact version");
|
|
|
|
// SystemCapsSl15 is not entirely correct for Streamline 1.3
|
|
// But we here only use the beginning that matches + extra
|
|
auto caps = (SystemCapsSl15*) value;
|
|
|
|
if (caps)
|
|
{
|
|
caps->gpuCount = 1;
|
|
caps->architecture[0] = UINT_MAX;
|
|
caps->driverVersionMajor = 999;
|
|
|
|
// HAGS
|
|
*((char*) value + 56) = (char) 0x01;
|
|
}
|
|
}
|
|
|
|
return o_setVoid(self, key, value);
|
|
}
|
|
|
|
void StreamlineHooks::hkcommon_slSetParameters_sl1(void* params)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
if (o_setVoid == nullptr && params)
|
|
{
|
|
void** vtable = *(void***) params;
|
|
|
|
// It's flipped, 0 -> set void*, 7 -> get void*
|
|
o_setVoid = (PFN_setVoid) vtable[0];
|
|
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
if (o_setVoid != nullptr)
|
|
DetourAttach(&(PVOID&) o_setVoid, hk_setVoid);
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
|
|
o_common_slSetParameters_sl1(params);
|
|
}
|
|
|
|
void* StreamlineHooks::hkcommon_slGetPluginFunction(const char* functionName)
|
|
{
|
|
// LOG_DEBUG("{}", functionName);
|
|
|
|
if (strcmp(functionName, "slOnPluginLoad") == 0)
|
|
{
|
|
o_common_slOnPluginLoad = (PFN_slOnPluginLoad) o_common_slGetPluginFunction(functionName);
|
|
return &hkcommon_slOnPluginLoad;
|
|
}
|
|
|
|
// Used around Streamline v1.3, as 1.5 doesn't seem to have it anymore
|
|
if (strcmp(functionName, "slSetParameters") == 0)
|
|
{
|
|
o_common_slSetParameters_sl1 = (PFN_slSetParameters_sl1) o_common_slGetPluginFunction(functionName);
|
|
return &hkcommon_slSetParameters_sl1;
|
|
}
|
|
|
|
return o_common_slGetPluginFunction(functionName);
|
|
}
|
|
|
|
void StreamlineHooks::updateForceReflex()
|
|
{
|
|
// Not needed for Streamline v1 as slSetConstants is sent every frame
|
|
if (o_slReflexSetOptions)
|
|
{
|
|
sl::ReflexOptions options;
|
|
|
|
auto forceReflex = Config::Instance()->FN_ForceReflex.value_or_default();
|
|
|
|
if (forceReflex == 2)
|
|
options.mode = sl::ReflexMode::eLowLatencyWithBoost;
|
|
else if (forceReflex == 1)
|
|
options.mode = sl::ReflexMode::eOff;
|
|
else if (forceReflex == 0)
|
|
options.mode = reflexGamesLastMode;
|
|
|
|
auto result = o_slReflexSetOptions(options);
|
|
}
|
|
}
|
|
|
|
// SL INTERPOSER
|
|
|
|
void StreamlineHooks::unhookInterposer()
|
|
{
|
|
LOG_FUNC();
|
|
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
if (o_slSetTag)
|
|
{
|
|
DetourDetach(&(PVOID&) o_slSetTag, hkslSetTag);
|
|
o_slSetTag = nullptr;
|
|
}
|
|
|
|
if (o_slInit)
|
|
{
|
|
DetourDetach(&(PVOID&) o_slInit, hkslInit);
|
|
o_slInit = nullptr;
|
|
}
|
|
|
|
if (o_slInit_sl1)
|
|
{
|
|
DetourDetach(&(PVOID&) o_slInit_sl1, hkslInit_sl1);
|
|
o_slInit_sl1 = nullptr;
|
|
}
|
|
|
|
o_logCallback_sl1 = nullptr;
|
|
o_logCallback = nullptr;
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
|
|
// Call it just after sl.interposer's load or if sl.interposer is already loaded
|
|
void StreamlineHooks::hookInterposer(HMODULE slInterposer)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
if (!slInterposer)
|
|
{
|
|
LOG_WARN("Streamline module in NULL");
|
|
return;
|
|
}
|
|
|
|
// Interposer needs this or it might end in an infinite loop calling itself
|
|
static HMODULE last_slInterposer = nullptr;
|
|
|
|
if (last_slInterposer == slInterposer)
|
|
return;
|
|
|
|
last_slInterposer = slInterposer;
|
|
|
|
// Looks like when reading DLL version load methods are called
|
|
// To prevent loops disabling checks for sl.interposer.dll
|
|
State::DisableChecks(7, "sl.interposer");
|
|
|
|
if (o_slSetTag || o_slInit || o_slInit_sl1)
|
|
unhookInterposer();
|
|
|
|
{
|
|
char dllPath[MAX_PATH];
|
|
GetModuleFileNameA(slInterposer, dllPath, MAX_PATH);
|
|
|
|
LOG_TRACE("slInterposer path: {}", dllPath);
|
|
|
|
Util::version_t sl_version;
|
|
Util::GetDLLVersion(string_to_wstring(dllPath), &sl_version);
|
|
|
|
State::Instance().streamlineVersion.major = sl_version.major;
|
|
State::Instance().streamlineVersion.minor = sl_version.minor;
|
|
State::Instance().streamlineVersion.patch = sl_version.patch;
|
|
|
|
LOG_INFO("Streamline version: {}.{}.{}", sl_version.major, sl_version.minor, sl_version.patch);
|
|
|
|
if (sl_version.major >= 2)
|
|
{
|
|
o_slSetTag =
|
|
reinterpret_cast<decltype(&slSetTag)>(KernelBaseProxy::GetProcAddress_()(slInterposer, "slSetTag"));
|
|
o_slSetTagForFrame = reinterpret_cast<decltype(&slSetTagForFrame)>(
|
|
KernelBaseProxy::GetProcAddress_()(slInterposer, "slSetTagForFrame"));
|
|
o_slInit = reinterpret_cast<decltype(&slInit)>(KernelBaseProxy::GetProcAddress_()(slInterposer, "slInit"));
|
|
o_slEvaluateFeature = reinterpret_cast<decltype(&slEvaluateFeature)>(
|
|
KernelBaseProxy::GetProcAddress_()(slInterposer, "slEvaluateFeature"));
|
|
o_slAllocateResources = reinterpret_cast<decltype(&slAllocateResources)>(
|
|
KernelBaseProxy::GetProcAddress_()(slInterposer, "slAllocateResources"));
|
|
o_slSetConstants = reinterpret_cast<decltype(&slSetConstants)>(
|
|
KernelBaseProxy::GetProcAddress_()(slInterposer, "slSetConstants"));
|
|
o_slGetNativeInterface = reinterpret_cast<decltype(&slGetNativeInterface)>(
|
|
KernelBaseProxy::GetProcAddress_()(slInterposer, "slGetNativeInterface"));
|
|
o_slSetD3DDevice = reinterpret_cast<decltype(&slSetD3DDevice)>(
|
|
KernelBaseProxy::GetProcAddress_()(slInterposer, "slSetD3DDevice"));
|
|
o_slGetNewFrameToken = reinterpret_cast<decltype(&slGetNewFrameToken)>(
|
|
KernelBaseProxy::GetProcAddress_()(slInterposer, "slGetNewFrameToken")); // Not hooked
|
|
|
|
if (o_slInit != nullptr)
|
|
{
|
|
LOG_TRACE("Hooking v2");
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
DetourAttach(&(PVOID&) o_slInit, hkslInit);
|
|
|
|
bool hookSetTag = (State::Instance().activeFgInput == FGInput::Nukems ||
|
|
State::Instance().activeFgInput == FGInput::DLSSG);
|
|
|
|
if (o_slSetTag != nullptr && hookSetTag)
|
|
DetourAttach(&(PVOID&) o_slSetTag, hkslSetTag);
|
|
|
|
if (o_slSetTagForFrame != nullptr && hookSetTag)
|
|
DetourAttach(&(PVOID&) o_slSetTagForFrame, hkslSetTagForFrame);
|
|
|
|
if (o_slSetConstants != nullptr && hookSetTag)
|
|
DetourAttach(&(PVOID&) o_slSetConstants, hkslSetConstants);
|
|
|
|
// if (o_slEvaluateFeature != nullptr)
|
|
// DetourAttach(&(PVOID&) o_slEvaluateFeature, hkslEvaluateFeature);
|
|
|
|
// if (o_slAllocateResources != nullptr)
|
|
// DetourAttach(&(PVOID&) o_slAllocateResources, hkslAllocateResources);
|
|
|
|
// if (o_slGetNativeInterface != nullptr)
|
|
// DetourAttach(&(PVOID&) o_slGetNativeInterface, hkslGetNativeInterface);
|
|
|
|
// if (o_slSetD3DDevice != nullptr)
|
|
// DetourAttach(&(PVOID&) o_slSetD3DDevice, hkslSetD3DDevice);
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
}
|
|
else if (sl_version.major == 1)
|
|
{
|
|
if (State::Instance().activeFgInput == FGInput::DLSSG)
|
|
State::Instance().activeFgInput = FGInput::NoFG;
|
|
|
|
o_slInit_sl1 =
|
|
reinterpret_cast<decltype(&sl1::slInit)>(KernelBaseProxy::GetProcAddress_()(slInterposer, "slInit"));
|
|
|
|
if (o_slInit_sl1)
|
|
{
|
|
LOG_TRACE("Hooking v1");
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
DetourAttach(&(PVOID&) o_slInit_sl1, hkslInit_sl1);
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
}
|
|
}
|
|
|
|
State::EnableChecks(7);
|
|
}
|
|
|
|
// SL DLSS
|
|
|
|
void StreamlineHooks::unhookDlss()
|
|
{
|
|
LOG_FUNC();
|
|
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
if (o_dlss_slGetPluginFunction)
|
|
{
|
|
DetourDetach(&(PVOID&) o_dlss_slGetPluginFunction, hkdlss_slGetPluginFunction);
|
|
o_dlss_slGetPluginFunction = nullptr;
|
|
}
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
|
|
void StreamlineHooks::hookDlss(HMODULE slDlss)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
if (!slDlss)
|
|
{
|
|
LOG_WARN("Dlss module in NULL");
|
|
return;
|
|
}
|
|
|
|
if (o_dlss_slGetPluginFunction)
|
|
unhookDlss();
|
|
|
|
o_dlss_slGetPluginFunction =
|
|
reinterpret_cast<PFN_slGetPluginFunction>(KernelBaseProxy::GetProcAddress_()(slDlss, "slGetPluginFunction"));
|
|
|
|
if (o_dlss_slGetPluginFunction != nullptr)
|
|
{
|
|
LOG_TRACE("Hooking slGetPluginFunction in sl.dlss");
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
DetourAttach(&(PVOID&) o_dlss_slGetPluginFunction, hkdlss_slGetPluginFunction);
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
}
|
|
|
|
// SL DLSSG
|
|
|
|
void StreamlineHooks::unhookDlssg()
|
|
{
|
|
LOG_FUNC();
|
|
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
if (o_dlssg_slGetPluginFunction)
|
|
{
|
|
DetourDetach(&(PVOID&) o_dlssg_slGetPluginFunction, hkdlssg_slGetPluginFunction);
|
|
o_dlssg_slGetPluginFunction = nullptr;
|
|
}
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
|
|
void StreamlineHooks::hookDlssg(HMODULE slDlssg)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
if (!slDlssg)
|
|
{
|
|
LOG_WARN("Dlssg module in NULL");
|
|
return;
|
|
}
|
|
|
|
if (o_dlssg_slGetPluginFunction)
|
|
unhookDlssg();
|
|
|
|
o_dlssg_slGetPluginFunction =
|
|
reinterpret_cast<PFN_slGetPluginFunction>(KernelBaseProxy::GetProcAddress_()(slDlssg, "slGetPluginFunction"));
|
|
|
|
if (o_dlssg_slGetPluginFunction != nullptr)
|
|
{
|
|
LOG_TRACE("Hooking slGetPluginFunction in sl.dlssg");
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
DetourAttach(&(PVOID&) o_dlssg_slGetPluginFunction, hkdlssg_slGetPluginFunction);
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
}
|
|
|
|
// SL REFLEX
|
|
|
|
void StreamlineHooks::unhookReflex()
|
|
{
|
|
LOG_FUNC();
|
|
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
if (o_reflex_slGetPluginFunction)
|
|
{
|
|
DetourDetach(&(PVOID&) o_reflex_slGetPluginFunction, hkreflex_slGetPluginFunction);
|
|
o_reflex_slGetPluginFunction = nullptr;
|
|
}
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
|
|
void StreamlineHooks::hookReflex(HMODULE slReflex)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
if (!slReflex)
|
|
{
|
|
LOG_WARN("Reflex module in NULL");
|
|
return;
|
|
}
|
|
|
|
if (o_reflex_slGetPluginFunction)
|
|
unhookReflex();
|
|
|
|
o_reflex_slGetPluginFunction =
|
|
reinterpret_cast<PFN_slGetPluginFunction>(KernelBaseProxy::GetProcAddress_()(slReflex, "slGetPluginFunction"));
|
|
|
|
if (o_reflex_slGetPluginFunction != nullptr)
|
|
{
|
|
LOG_TRACE("Hooking slGetPluginFunction in sl.reflex");
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
DetourAttach(&(PVOID&) o_reflex_slGetPluginFunction, hkreflex_slGetPluginFunction);
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
}
|
|
|
|
// SL PCL
|
|
|
|
void StreamlineHooks::unhookPcl()
|
|
{
|
|
LOG_FUNC();
|
|
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
if (o_pcl_slGetPluginFunction)
|
|
{
|
|
DetourDetach(&(PVOID&) o_pcl_slGetPluginFunction, hkpcl_slGetPluginFunction);
|
|
o_pcl_slGetPluginFunction = nullptr;
|
|
}
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
|
|
void StreamlineHooks::hookPcl(HMODULE slPcl)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
if (!slPcl)
|
|
{
|
|
LOG_WARN("Pcl module in NULL");
|
|
return;
|
|
}
|
|
|
|
if (o_pcl_slGetPluginFunction)
|
|
unhookPcl();
|
|
|
|
o_pcl_slGetPluginFunction =
|
|
reinterpret_cast<PFN_slGetPluginFunction>(KernelBaseProxy::GetProcAddress_()(slPcl, "slGetPluginFunction"));
|
|
|
|
if (o_pcl_slGetPluginFunction != nullptr)
|
|
{
|
|
LOG_TRACE("Hooking slGetPluginFunction in sl.pcl");
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
DetourAttach(&(PVOID&) o_pcl_slGetPluginFunction, hkpcl_slGetPluginFunction);
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
}
|
|
|
|
// SL COMMON
|
|
|
|
void StreamlineHooks::unhookCommon()
|
|
{
|
|
LOG_FUNC();
|
|
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
if (o_common_slGetPluginFunction)
|
|
{
|
|
DetourDetach(&(PVOID&) o_common_slGetPluginFunction, hkcommon_slGetPluginFunction);
|
|
o_common_slGetPluginFunction = nullptr;
|
|
}
|
|
|
|
systemCaps = nullptr;
|
|
systemCapsSl15 = nullptr;
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
|
|
void StreamlineHooks::hookCommon(HMODULE slCommon)
|
|
{
|
|
LOG_FUNC();
|
|
|
|
if (!slCommon)
|
|
{
|
|
LOG_WARN("Common module in NULL");
|
|
return;
|
|
}
|
|
|
|
if (o_common_slGetPluginFunction)
|
|
unhookCommon();
|
|
|
|
o_common_slGetPluginFunction =
|
|
reinterpret_cast<PFN_slGetPluginFunction>(KernelBaseProxy::GetProcAddress_()(slCommon, "slGetPluginFunction"));
|
|
|
|
if (o_common_slGetPluginFunction != nullptr)
|
|
{
|
|
LOG_TRACE("Hooking slGetPluginFunction in sl.common");
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
DetourAttach(&(PVOID&) o_common_slGetPluginFunction, hkcommon_slGetPluginFunction);
|
|
|
|
DetourTransactionCommit();
|
|
}
|
|
}
|
|
|
|
bool StreamlineHooks::isInterposerHooked() { return o_slInit != nullptr || o_slInit_sl1 != nullptr; }
|
|
|
|
bool StreamlineHooks::isDlssHooked() { return o_dlss_slGetPluginFunction != nullptr; }
|
|
|
|
bool StreamlineHooks::isDlssgHooked() { return o_dlssg_slGetPluginFunction != nullptr; }
|
|
|
|
bool StreamlineHooks::isCommonHooked() { return o_common_slGetPluginFunction != nullptr; }
|
|
|
|
bool StreamlineHooks::isPclHooked() { return o_pcl_slGetPluginFunction != nullptr; }
|
|
|
|
bool StreamlineHooks::isReflexHooked() { return o_reflex_slGetPluginFunction != nullptr; }
|