Add cheats
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
#define IMGUI_HAS_DOCK 1
|
||||
|
||||
#include "CommonHeaders.h"
|
||||
#include "HotkeysManager.h"
|
||||
#include "OSDManager.h"
|
||||
#include <chrono>
|
||||
#include <Windows.h>
|
||||
|
||||
// Screen informations
|
||||
@@ -17,11 +20,15 @@ typedef void (*SetFloatFn)(float);
|
||||
|
||||
static HMODULE fixLib = nullptr;
|
||||
static LONG g_coreInitialized = 0;
|
||||
static LONG g_hotkeysInitialized = 0;
|
||||
static LONG g_uniformReseted = 0;
|
||||
static SetBoolFn SetFixEnabled = nullptr;
|
||||
static SetFixesFn SetFixes = nullptr;
|
||||
static GetGameInfosStruct GetGameInfos = nullptr;
|
||||
static SetIntFn SetFOV = nullptr;
|
||||
static SetFloatFn SetCameraDistance = nullptr;
|
||||
static SetFloatFn SetWorldTimeDilation = nullptr;
|
||||
static SetFloatFn SetAITimeDilation = nullptr;
|
||||
void SetFixesEnabled(GameFixes fix, bool value) { if (SetFixes) SetFixes(fix, value); }
|
||||
|
||||
// Plugin variables for checkboxes and sliders
|
||||
@@ -33,9 +40,16 @@ static bool Vignetting_fix_enabled = false;
|
||||
static bool Fog_fix_enabled = false;
|
||||
static bool camera_Distance_fix_enabled = false;
|
||||
static bool fix_enabled = false;
|
||||
static bool Time_Dilation_fix_enabled = false;
|
||||
static bool Ignore_hits_fix_enabled = false;
|
||||
static bool StealthMode_fix_enabled = false;
|
||||
static bool GodMode_fix_enabled = false;
|
||||
static int worldFOVvalue = 0;
|
||||
static float cameraDistancevalue = 0.f;
|
||||
static float worldTimeDilationValue = 1.f;
|
||||
static float AITimeDilationValue = 1.f;
|
||||
static bool console = true;
|
||||
static float OSD_duration = 3.f;
|
||||
|
||||
// Overlays popups
|
||||
static bool popup_Informations = false;
|
||||
@@ -59,10 +73,17 @@ static FixToggle individualFixes[] = {
|
||||
{ "Depth of field", &DOF_fix_enabled, GameFixes::DOF }
|
||||
};
|
||||
|
||||
static FixToggle cheatFixes[] = {
|
||||
{ "Time dilation", &Time_Dilation_fix_enabled, GameFixes::TimeDilation, "ALT + 1 (top keyboard row) to toggle" },
|
||||
{ "God mode", &GodMode_fix_enabled, GameFixes::GodMode, "ALT + 2 (top keyboard row) to toggle.\nTraveler won't receive any damage." },
|
||||
{ "Ignore hits", &Ignore_hits_fix_enabled, GameFixes::IgnoreHits, "ALT + 3 (top keyboard row) to toggle.\nTraveler can't be hit but still can be grabbed." },
|
||||
{ "Stealth mode",&StealthMode_fix_enabled, GameFixes::Stealth, "ALT + 4 (top keyboard row) to toggle.\nEnemies won't attack you" }
|
||||
};
|
||||
|
||||
// Facteur de scaling basé sur la résolution verticale
|
||||
float scale = (float)screenHeight / 1200;
|
||||
// Prepare array of sliders for ImGui
|
||||
static SliderFix sliders[2];
|
||||
static SliderFix sliders[4];
|
||||
|
||||
// Load and unload game core dll functions /!\ necessary
|
||||
static void LoadFixDLL() {
|
||||
@@ -81,11 +102,15 @@ static void LoadFixDLL() {
|
||||
SetFixes = (SetFixesFn)GetProcAddress(fixLib, "SetFixesEnabled");
|
||||
SetFOV = (SetIntFn)GetProcAddress(fixLib, "SetFOV");
|
||||
SetCameraDistance = (SetFloatFn)GetProcAddress(fixLib, "SetCameraDistance");
|
||||
SetWorldTimeDilation = (SetFloatFn)GetProcAddress(fixLib, "SetWorldTimeDilation");
|
||||
SetAITimeDilation = (SetFloatFn)GetProcAddress(fixLib, "SetAITimeDilation");
|
||||
GetGameInfos = (GetGameInfosStruct)GetProcAddress(fixLib, "GetGameInfos");
|
||||
|
||||
// Apply initial values loaded from settings
|
||||
if (SetFOV) SetFOV(worldFOVvalue);
|
||||
if (SetCameraDistance) SetCameraDistance(cameraDistancevalue);
|
||||
if (SetWorldTimeDilation) SetWorldTimeDilation(worldTimeDilationValue);
|
||||
if (SetAITimeDilation) SetAITimeDilation(AITimeDilationValue);
|
||||
if (SetFixEnabled) SetFixEnabled(fix_enabled, true);
|
||||
if (SetFixes) {
|
||||
SetFixes(GameFixes::SkipIntro, skip_Intro_enabled);
|
||||
@@ -95,12 +120,20 @@ static void LoadFixDLL() {
|
||||
SetFixes(GameFixes::DOF, DOF_fix_enabled);
|
||||
SetFixes(GameFixes::Vignetting, Vignetting_fix_enabled);
|
||||
SetFixes(GameFixes::Fog, Fog_fix_enabled);
|
||||
SetFixes(GameFixes::TimeDilation, Time_Dilation_fix_enabled);
|
||||
SetFixes(GameFixes::GodMode, GodMode_fix_enabled);
|
||||
SetFixes(GameFixes::IgnoreHits, Ignore_hits_fix_enabled);
|
||||
SetFixes(GameFixes::Stealth, StealthMode_fix_enabled);
|
||||
SetFixes(GameFixes::DevConsole, console);
|
||||
}
|
||||
|
||||
sliders[0] = { "In game additional FOV", "##FOVValue", SliderType::Int, &worldFOVvalue, -20, 70, SetFOV };
|
||||
sliders[1] = { "Camera distance (*)", "##CameraOffset", SliderType::Float, &cameraDistancevalue, 0, 4, SetCameraDistance, "%.2f",
|
||||
"Value is a multiplier.\nAffects both normal and weapon aiming distance." };
|
||||
sliders[2] = { "World time dilation", "##WorldTimeDilationValue", SliderType::Float, &worldTimeDilationValue, 0.f, 2.f, SetWorldTimeDilation, nullptr,
|
||||
"Will affect everything in the world.\nDefault value is 1." };
|
||||
sliders[3] = { "AI time dilation", "##AITimeDilationValue", SliderType::Float, &AITimeDilationValue, 0.f, 2.f, SetAITimeDilation, nullptr,
|
||||
"Will affect only enemies in the world.\nDefault value is 1." };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,9 +156,15 @@ static void SaveSettings() {
|
||||
pluginIniFile["2#Individual fix"]["DOF"] = DOF_fix_enabled;
|
||||
pluginIniFile["2#Individual fix"]["Vignetting"] = Vignetting_fix_enabled;
|
||||
pluginIniFile["2#Individual fix"]["Fog"] = Fog_fix_enabled;
|
||||
pluginIniFile["2#Individual fix"]["Time dilation"] = Time_Dilation_fix_enabled;
|
||||
pluginIniFile["2#Individual fix"]["God Mode"] = GodMode_fix_enabled;
|
||||
pluginIniFile["2#Individual fix"]["Ignore hits"] = Ignore_hits_fix_enabled;
|
||||
pluginIniFile["2#Individual fix"]["Stealth"] = StealthMode_fix_enabled;
|
||||
pluginIniFile["3#Fixes tuning"].setComment("Individual fix fine tune");
|
||||
pluginIniFile["3#Fixes tuning"]["World FOV"] = worldFOVvalue;
|
||||
pluginIniFile["3#Fixes tuning"]["Camera distance"] = cameraDistancevalue;
|
||||
pluginIniFile["3#Fixes tuning"]["World time dilation scale"] = worldTimeDilationValue;
|
||||
pluginIniFile["3#Fixes tuning"]["AI time dilation scale"] = AITimeDilationValue;
|
||||
|
||||
pluginIniFile.save(SETTINGS_FILE);
|
||||
}
|
||||
@@ -143,8 +182,14 @@ static void LoadSettings() {
|
||||
DOF_fix_enabled = pluginIniFile["2#Individual fix"]["DOF"].as<bool>();
|
||||
Vignetting_fix_enabled = pluginIniFile["2#Individual fix"]["Vignetting"].as<bool>();
|
||||
Fog_fix_enabled = pluginIniFile["2#Individual fix"]["Fog"].as<bool>();
|
||||
Time_Dilation_fix_enabled = pluginIniFile["2#Individual fix"]["Time dilation"].as<bool>();
|
||||
GodMode_fix_enabled = pluginIniFile["2#Individual fix"]["God Mode"].as<bool>();
|
||||
Ignore_hits_fix_enabled = pluginIniFile["2#Individual fix"]["Ignore hits"].as<bool>();
|
||||
StealthMode_fix_enabled = pluginIniFile["2#Individual fix"]["Stealth"].as<bool>();
|
||||
worldFOVvalue = pluginIniFile["3#Fixes tuning"]["World FOV"].as<int>();
|
||||
cameraDistancevalue = pluginIniFile["3#Fixes tuning"]["Camera distance"].as<float>();
|
||||
worldTimeDilationValue = pluginIniFile["3#Fixes tuning"]["World time dilation scale"].as<float>();
|
||||
AITimeDilationValue = pluginIniFile["3#Fixes tuning"]["AI time dilation scale"].as<float>();
|
||||
}
|
||||
catch (const std::exception& e) {}
|
||||
}
|
||||
@@ -199,53 +244,110 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if (ImGui::BeginTable("FixesTable", 2, ImGuiTableFlags_SizingStretchSame)) {
|
||||
ImGui::TableSetupColumn("LeftFix", ImGuiTableColumnFlags_WidthStretch, 0.4f);
|
||||
ImGui::TableSetupColumn("RightFix", ImGuiTableColumnFlags_WidthStretch, 0.6f);
|
||||
ImGui::TableNextRow();
|
||||
if (ImGui::BeginTabBar("MainTabs")) {
|
||||
if (ImGui::BeginTabItem("Fixes")) {
|
||||
if (ImGui::BeginTable("FixesTable", 2, ImGuiTableFlags_SizingStretchSame)) {
|
||||
ImGui::TableSetupColumn("LeftFix", ImGuiTableColumnFlags_WidthStretch, 0.4f);
|
||||
ImGui::TableSetupColumn("RightFix", ImGuiTableColumnFlags_WidthStretch, 0.6f);
|
||||
ImGui::TableNextRow();
|
||||
|
||||
// Drawing a left column with slider and general fix
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
// Drawing a left column with slider and general fix
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
|
||||
// Drawing a left column with slider and general fix
|
||||
if (ImGui::CollapsingHeader("Enable fixes", ImGuiTreeNodeFlags_DefaultOpen))
|
||||
if (ImGui::Checkbox("Fix enabled", &fix_enabled)) { if (SetFixEnabled) SetFixEnabled(fix_enabled, false); SaveSettings(); }
|
||||
// Drawing a left column with slider and general fix
|
||||
if (ImGui::CollapsingHeader("Enable fixes", ImGuiTreeNodeFlags_DefaultOpen))
|
||||
if (ImGui::Checkbox("Fix enabled", &fix_enabled)) { if (SetFixEnabled) SetFixEnabled(fix_enabled, false); SaveSettings(); }
|
||||
|
||||
// Sliders
|
||||
for (int i = 0; i < 2; ++i) DrawSlider(sliders[i], 150);
|
||||
// Sliders
|
||||
for (int i = 0; i < 2; ++i) DrawSlider(sliders[i], 150);
|
||||
|
||||
// Individual fixes
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
if (ImGui::CollapsingHeader("Individual fixes", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
if (ImGui::BeginTable("IndividualFixesTable", 2, ImGuiTableFlags_SizingStretchSame)) {
|
||||
ImGui::TableSetupColumn("IndFix1", ImGuiTableColumnFlags_WidthStretch, 0.4f);
|
||||
ImGui::TableSetupColumn("IndFix2", ImGuiTableColumnFlags_WidthStretch, 0.6f);
|
||||
// Individual fixes
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
if (ImGui::CollapsingHeader("Individual fixes", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
if (ImGui::BeginTable("IndividualFixesTable", 2, ImGuiTableFlags_SizingStretchSame)) {
|
||||
ImGui::TableSetupColumn("IndFix1", ImGuiTableColumnFlags_WidthStretch, 0.4f);
|
||||
ImGui::TableSetupColumn("IndFix2", ImGuiTableColumnFlags_WidthStretch, 0.6f);
|
||||
ImGui::TableNextRow();
|
||||
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
for (int i = 0; i < 3; ++i) DrawFixCheckbox(individualFixes[i]);
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
for (int i = 3; i < IM_ARRAYSIZE(individualFixes); ++i) DrawFixCheckbox(individualFixes[i]);
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui::BeginTabItem("Cheats")) {
|
||||
for (const auto& cheat : cheatFixes) DrawFixCheckbox(cheat);
|
||||
|
||||
if (ImGui::BeginTable("SlidersTable", 2, ImGuiTableFlags_SizingStretchSame)) {
|
||||
ImGui::TableSetupColumn("LeftSliders", ImGuiTableColumnFlags_WidthStretch, 0.5f);
|
||||
ImGui::TableSetupColumn("RightSliders", ImGuiTableColumnFlags_WidthStretch, 0.5f);
|
||||
ImGui::TableNextRow();
|
||||
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
for (int i = 0; i < 3; ++i) DrawFixCheckbox(individualFixes[i]);
|
||||
DrawSlider(sliders[2], 180);
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
for (int i = 3; i < IM_ARRAYSIZE(individualFixes); ++i) DrawFixCheckbox(individualFixes[i]);
|
||||
DrawSlider(sliders[3], 180);
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::EndTabBar();
|
||||
|
||||
// Fix status
|
||||
if (ImGui::CollapsingHeader("Fix informations", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
ImGui::Text("Screen width: %d, height: %d, aspect ratio: %.2f", screenWidth, screenHeight, aspectRatio);
|
||||
if (GetGameInfos) {
|
||||
GameInfos infos{};
|
||||
GetGameInfos(&infos);
|
||||
if (infos.consoleEnabled)
|
||||
ImGui::Text("Console enabled and bound to key Tilde");
|
||||
ImGui::TextColored(ImColor(48, 179, 25), "FOV In: %.2f, Compensated: %.2f, Out: %.2f", infos.FOVIn, infos.CompensatedFOV, infos.FOVOut);
|
||||
ImGui::TextColored(ImColor(48, 179, 25), "Camera distance In: %.2f, Out: %.2f", infos.cameraIn, infos.cameraOut);
|
||||
// Fix status
|
||||
if (ImGui::CollapsingHeader("Fix informations", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
ImGui::Text("Screen width: %d, height: %d, aspect ratio: %.2f", screenWidth, screenHeight, aspectRatio);
|
||||
if (GetGameInfos) {
|
||||
GameInfos infos{};
|
||||
GetGameInfos(&infos);
|
||||
if (infos.consoleEnabled)
|
||||
ImGui::Text("Console enabled and bound to key F2");
|
||||
ImGui::TextColored(ImColor(48, 179, 25), "FOV In: %.2f, Compensated: %.2f, Out: %.2f", infos.FOVIn, infos.CompensatedFOV, infos.FOVOut);
|
||||
ImGui::TextColored(ImColor(48, 179, 25), "Camera distance In: %.2f, Out: %.2f", infos.cameraIn, infos.cameraOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void on_reshade_present(reshade::api::effect_runtime* runtime) {
|
||||
static auto last = std::chrono::steady_clock::now();
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
float dt = std::chrono::duration<float>(now - last).count();
|
||||
last = now;
|
||||
|
||||
ProcessHotkeys(runtime);
|
||||
UpdateOSD(runtime, dt);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if (!runtime) return;
|
||||
FindAllUniformVariables(runtime, OSD_SHADER_NAME); // Find all uniforms and set their handle
|
||||
|
||||
if (InterlockedCompareExchange(&g_uniformReseted, 1, 0) != 0) return; // reset OSD uniforms once
|
||||
ResetAllUniformVariables(runtime, OSD_SHADER_NAME);
|
||||
runtime->save_current_preset(); // Save shader preset
|
||||
}
|
||||
|
||||
static void InitializeHotkeys() { // Initialize hotkeys for cheats
|
||||
if (InterlockedCompareExchange(&g_hotkeysInitialized, 1, 0) != 0) return; // Initialize hotkeys once
|
||||
|
||||
RegisterHotkey('1', Modifier::Alt, [] {
|
||||
ToggleOSD(Time_Dilation_fix_enabled, GameFixes::TimeDilation,
|
||||
u_td_show, u_td_enabled, OSD_duration,
|
||||
{ {u_td_world, worldTimeDilationValue}, {u_td_AI, AITimeDilationValue} });
|
||||
});
|
||||
RegisterHotkey('2', Modifier::Alt, [] { ToggleOSD(GodMode_fix_enabled, GameFixes::GodMode, u_GodMode_show, u_GodMode_enabled, OSD_duration); });
|
||||
RegisterHotkey('3', Modifier::Alt, [] { ToggleOSD(Ignore_hits_fix_enabled, GameFixes::IgnoreHits, u_IgnoreHits_show, u_IgnoreHits_enabled, OSD_duration); });
|
||||
RegisterHotkey('4', Modifier::Alt, [] { ToggleOSD(StealthMode_fix_enabled, GameFixes::Stealth, u_Stealth_show, u_Stealth_enabled, OSD_duration); });
|
||||
}
|
||||
|
||||
// Main dll intrance
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID) {
|
||||
switch (ul_reason_for_call) {
|
||||
@@ -258,9 +360,14 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID) {
|
||||
reshade::register_event<reshade::addon_event::init_effect_runtime>(
|
||||
[](reshade::api::effect_runtime* runtime) {
|
||||
LoadFixDLL();
|
||||
InitializeHotkeys();
|
||||
});
|
||||
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;
|
||||
case DLL_PROCESS_DETACH:
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user