Add OSD shader driving
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <reshade.hpp>
|
#include <reshade.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
// Screen informations
|
// Screen informations
|
||||||
@@ -40,7 +41,6 @@ static bool CA_fix_enabled = false;
|
|||||||
static bool Vignetting_fix_enabled = false;
|
static bool Vignetting_fix_enabled = false;
|
||||||
static bool Fog_fix_enabled = false;
|
static bool Fog_fix_enabled = false;
|
||||||
static bool Time_Dilation_fix_enabled = false;
|
static bool Time_Dilation_fix_enabled = false;
|
||||||
static bool prev_TimeDilation = Time_Dilation_fix_enabled;
|
|
||||||
static bool fix_enabled = false;
|
static bool fix_enabled = false;
|
||||||
static bool console = true;
|
static bool console = true;
|
||||||
static int worldFOVValue = 0;
|
static int worldFOVValue = 0;
|
||||||
@@ -49,12 +49,19 @@ static int cameraOffsetValue = 0;
|
|||||||
static float worldTimeDilationValue = 1.f;
|
static float worldTimeDilationValue = 1.f;
|
||||||
static float AITimeDilationValue = 1.f;
|
static float AITimeDilationValue = 1.f;
|
||||||
static float cameraSmoothnessValue = 3.5f;
|
static float cameraSmoothnessValue = 3.5f;
|
||||||
|
static float OSD_duration = 3.f;
|
||||||
|
|
||||||
// Overlays popups
|
// Overlays popups
|
||||||
static bool popup_Informations = false;
|
static bool popup_Informations = false;
|
||||||
static bool show_log_overlay = false;
|
static bool show_log_overlay = false;
|
||||||
static std::string log_content;
|
static std::string log_content;
|
||||||
|
|
||||||
|
// Shader toggles
|
||||||
|
static reshade::api::effect_uniform_variable u_td_show = {};
|
||||||
|
static reshade::api::effect_uniform_variable u_td_enabled = {};
|
||||||
|
static reshade::api::effect_uniform_variable u_td_world = {};
|
||||||
|
static reshade::api::effect_uniform_variable u_td_AI = {};
|
||||||
|
|
||||||
// Plugin settings
|
// Plugin settings
|
||||||
const std::string SETTINGS_FILE = "./pluginsettings.ini";
|
const std::string SETTINGS_FILE = "./pluginsettings.ini";
|
||||||
const char* FIX_VERSION = "0.9.5";
|
const char* FIX_VERSION = "0.9.5";
|
||||||
@@ -64,6 +71,7 @@ const char* DONATION_URL = "https://buymeacoffee.com/k4sh44";
|
|||||||
// Scaling factor based on screen resolution
|
// Scaling factor based on screen resolution
|
||||||
float scale = (float)screenHeight / 1200;
|
float scale = (float)screenHeight / 1200;
|
||||||
|
|
||||||
|
// Plugin sig
|
||||||
extern "C" __declspec(dllexport) const char* NAME = "The Callisto Protocol";
|
extern "C" __declspec(dllexport) const char* NAME = "The Callisto Protocol";
|
||||||
extern "C" __declspec(dllexport) const char* DESCRIPTION = "Reshade addon to re-enable console, control FOV, camera distance, time dilation, HUD and some effects.";
|
extern "C" __declspec(dllexport) const char* DESCRIPTION = "Reshade addon to re-enable console, control FOV, camera distance, time dilation, HUD and some effects.";
|
||||||
|
|
||||||
@@ -124,6 +132,7 @@ static void SaveSettings()
|
|||||||
"Set Console to false if you don't want dev console to be enabled"});
|
"Set Console to false if you don't want dev console to be enabled"});
|
||||||
pluginIniFile["1#General fix"]["Enabled"] = fix_enabled;
|
pluginIniFile["1#General fix"]["Enabled"] = fix_enabled;
|
||||||
pluginIniFile["1#General fix"]["Console"] = console;
|
pluginIniFile["1#General fix"]["Console"] = console;
|
||||||
|
pluginIniFile["1#General fix"]["OSD duration"] = OSD_duration;
|
||||||
pluginIniFile["2#Individual fix"].setComment("Controls each fix individually");
|
pluginIniFile["2#Individual fix"].setComment("Controls each fix individually");
|
||||||
pluginIniFile["2#Individual fix"]["FOV"] = fov_fix_enabled;
|
pluginIniFile["2#Individual fix"]["FOV"] = fov_fix_enabled;
|
||||||
pluginIniFile["2#Individual fix"]["Camera"] = Camera_fix_enabled;
|
pluginIniFile["2#Individual fix"]["Camera"] = Camera_fix_enabled;
|
||||||
@@ -150,6 +159,7 @@ static void LoadSettings()
|
|||||||
pluginIniFile.load(SETTINGS_FILE);
|
pluginIniFile.load(SETTINGS_FILE);
|
||||||
fix_enabled = pluginIniFile["1#General fix"]["Enabled"].as<bool>();
|
fix_enabled = pluginIniFile["1#General fix"]["Enabled"].as<bool>();
|
||||||
console = pluginIniFile["1#General fix"]["Console"].as<bool>();
|
console = pluginIniFile["1#General fix"]["Console"].as<bool>();
|
||||||
|
OSD_duration = pluginIniFile["1#General fix"]["OSD duration"].as<float>();
|
||||||
fov_fix_enabled = pluginIniFile["2#Individual fix"]["FOV"].as<bool>();
|
fov_fix_enabled = pluginIniFile["2#Individual fix"]["FOV"].as<bool>();
|
||||||
HUD_fix_enabled = pluginIniFile["2#Individual fix"]["HUD"].as<bool>();
|
HUD_fix_enabled = pluginIniFile["2#Individual fix"]["HUD"].as<bool>();
|
||||||
Camera_fix_enabled = pluginIniFile["2#Individual fix"]["Camera"].as<bool>();
|
Camera_fix_enabled = pluginIniFile["2#Individual fix"]["Camera"].as<bool>();
|
||||||
@@ -168,17 +178,18 @@ static void LoadSettings()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read plugin log file
|
// Read plugin log file
|
||||||
void read_log_file(const std::string& filename) {
|
static std::string read_log_file(const std::string& filename) {
|
||||||
std::ifstream file(filename);
|
std::ifstream file(filename);
|
||||||
if (!file.is_open())
|
std::string log;
|
||||||
{
|
if (!file.is_open()) {
|
||||||
log_content = "Impossible to open file : " + filename;
|
log = "Impossible to open file : " + filename;
|
||||||
return;
|
return log;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << file.rdbuf();
|
ss << file.rdbuf();
|
||||||
log_content = ss.str();
|
log = ss.str();
|
||||||
|
return log;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize ImGui widgets for Reshade
|
// Initialize ImGui widgets for Reshade
|
||||||
@@ -202,7 +213,7 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
|
|||||||
if (ImGui::Button("Fix informations")) popup_Informations = true; // Fix information
|
if (ImGui::Button("Fix informations")) popup_Informations = true; // Fix information
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("View logs")) {
|
if (ImGui::Button("View logs")) {
|
||||||
read_log_file("TheCallistoProtocol.log");
|
log_content = read_log_file("TheCallistoProtocol.log");
|
||||||
show_log_overlay = true; // Fix information
|
show_log_overlay = true; // Fix information
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,19 +292,18 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
|
|||||||
if (SetFixesEnabled) SetFixesEnabled(GameFixes::ChromaticAberrations, CA_fix_enabled);
|
if (SetFixesEnabled) SetFixesEnabled(GameFixes::ChromaticAberrations, CA_fix_enabled);
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sliders
|
||||||
if (ImGui::BeginTable("SlidersTable", 2, ImGuiTableFlags_SizingStretchSame)) {
|
if (ImGui::BeginTable("SlidersTable", 2, ImGuiTableFlags_SizingStretchSame)) {
|
||||||
ImGui::TableSetupColumn("LeftSliders", ImGuiTableColumnFlags_WidthStretch, 0.5f);
|
ImGui::TableSetupColumn("LeftSliders", ImGuiTableColumnFlags_WidthStretch, 0.5f);
|
||||||
ImGui::TableSetupColumn("RightSliders", ImGuiTableColumnFlags_WidthStretch, 0.5f);
|
ImGui::TableSetupColumn("RightSliders", ImGuiTableColumnFlags_WidthStretch, 0.5f);
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
|
|
||||||
// Sliders
|
|
||||||
ImGui::TableSetColumnIndex(0);
|
ImGui::TableSetColumnIndex(0);
|
||||||
if (ImGui::CollapsingHeader("In game additional FOV", ImGuiTreeNodeFlags_DefaultOpen))
|
if (ImGui::CollapsingHeader("In game additional FOV", ImGuiTreeNodeFlags_DefaultOpen))
|
||||||
{
|
{
|
||||||
@@ -346,7 +356,10 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
|
|||||||
|
|
||||||
if (ImGui::BeginTabItem("Cheats"))
|
if (ImGui::BeginTabItem("Cheats"))
|
||||||
{
|
{
|
||||||
ImGui::Checkbox("Time dilation", &Time_Dilation_fix_enabled);
|
if (ImGui::Checkbox("Time dilation", &Time_Dilation_fix_enabled)) {
|
||||||
|
if (SetFixesEnabled) SetFixesEnabled(GameFixes::WorldTimeDilation, Time_Dilation_fix_enabled);
|
||||||
|
SaveSettings();
|
||||||
|
}
|
||||||
if (ImGui::IsItemHovered()) {
|
if (ImGui::IsItemHovered()) {
|
||||||
ImGui::BeginTooltip();
|
ImGui::BeginTooltip();
|
||||||
ImGui::Text("Use ALT + F1 shortcut to de/activate.");
|
ImGui::Text("Use ALT + F1 shortcut to de/activate.");
|
||||||
@@ -409,19 +422,54 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void on_reshade_present(reshade::api::effect_runtime* runtime) {
|
static void on_reshade_present(reshade::api::effect_runtime* runtime) {
|
||||||
|
if (!runtime) return; // Ensure runtime is valid
|
||||||
|
|
||||||
static bool wasTimeDilationInvoked = false;
|
static bool wasTimeDilationInvoked = false;
|
||||||
|
static float OSD_local_duration = OSD_duration;
|
||||||
|
static auto last_time = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
// ---- Delta time ----
|
||||||
|
auto now = std::chrono::steady_clock::now();
|
||||||
|
float delta_time = std::chrono::duration<float>(now - last_time).count();
|
||||||
|
last_time = now;
|
||||||
|
|
||||||
|
// ---- ALT+F1 toggle ----
|
||||||
bool timeDilationInvoked = runtime->is_key_down(VK_MENU) && runtime->is_key_down(VK_F1);
|
bool timeDilationInvoked = runtime->is_key_down(VK_MENU) && runtime->is_key_down(VK_F1);
|
||||||
|
|
||||||
if (timeDilationInvoked && !wasTimeDilationInvoked)
|
if (timeDilationInvoked && !wasTimeDilationInvoked)
|
||||||
|
{
|
||||||
Time_Dilation_fix_enabled = !Time_Dilation_fix_enabled;
|
Time_Dilation_fix_enabled = !Time_Dilation_fix_enabled;
|
||||||
|
OSD_local_duration = OSD_duration;
|
||||||
|
|
||||||
|
// Apply values in the shader
|
||||||
|
if (u_td_show.handle && u_td_enabled.handle && u_td_world.handle && u_td_AI.handle) {
|
||||||
|
runtime->set_uniform_value_bool(u_td_enabled, Time_Dilation_fix_enabled);
|
||||||
|
runtime->set_uniform_value_bool(u_td_show, true);
|
||||||
|
runtime->set_uniform_value_float(u_td_world, worldTimeDilationValue);
|
||||||
|
runtime->set_uniform_value_float(u_td_AI, AITimeDilationValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SetFixesEnabled) SetFixesEnabled(GameFixes::WorldTimeDilation, Time_Dilation_fix_enabled);
|
||||||
|
SaveSettings();
|
||||||
|
}
|
||||||
wasTimeDilationInvoked = timeDilationInvoked;
|
wasTimeDilationInvoked = timeDilationInvoked;
|
||||||
|
|
||||||
if (prev_TimeDilation != Time_Dilation_fix_enabled) {
|
if (OSD_local_duration > 0.0f) { // ---- Timer to hide OSD ----
|
||||||
if (SetFixesEnabled) SetFixesEnabled(GameFixes::WorldTimeDilation, Time_Dilation_fix_enabled); // Apply cheat
|
OSD_local_duration -= delta_time;
|
||||||
SaveSettings();
|
if (OSD_local_duration <= 0.0f) {
|
||||||
prev_TimeDilation = Time_Dilation_fix_enabled;
|
if (u_td_show.handle) runtime->set_uniform_value_bool(u_td_show, false);
|
||||||
|
|
||||||
|
OSD_local_duration = 0.0f;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve all shader uniform variables
|
||||||
|
static void on_reshade_begin_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list,
|
||||||
|
reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) {
|
||||||
|
u_td_show = runtime->find_uniform_variable(nullptr, "TD_Show");
|
||||||
|
u_td_enabled = runtime->find_uniform_variable(nullptr, "TD_Enabled");
|
||||||
|
u_td_world = runtime->find_uniform_variable(nullptr, "TD_World");
|
||||||
|
u_td_AI = runtime->find_uniform_variable(nullptr, "TD_AI");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main dll intrance
|
// Main dll intrance
|
||||||
@@ -440,9 +488,11 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID)
|
|||||||
LoadFixDLL();
|
LoadFixDLL();
|
||||||
});
|
});
|
||||||
reshade::register_event<reshade::addon_event::reshade_present>(&on_reshade_present);
|
reshade::register_event<reshade::addon_event::reshade_present>(&on_reshade_present);
|
||||||
|
reshade::register_event<reshade::addon_event::reshade_begin_effects>(&on_reshade_begin_effects);
|
||||||
break;
|
break;
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
reshade::unregister_event<reshade::addon_event::reshade_present>(&on_reshade_present);
|
reshade::unregister_event<reshade::addon_event::reshade_present>(&on_reshade_present);
|
||||||
|
reshade::unregister_event<reshade::addon_event::reshade_begin_effects>(&on_reshade_begin_effects);
|
||||||
reshade::unregister_addon(hinstDLL);
|
reshade::unregister_addon(hinstDLL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user