Bind checkboxes

  • K4sh
  • Topic Author
More
11 months 1 week ago #1 by K4sh Bind checkboxes was created by K4sh
So i have made an addon with a couple of checkboxes.
Is it possible to bind shortcuts (eq ALT + F1, F2 ...) to these checkboxes ?

Please Log in or Create an account to join the conversation.

  • crosire
More
11 months 1 week ago #2 by crosire Replied by crosire on topic Bind checkboxes
You can simply check the key state and toggle the same value that the checkbox is affecting:
Code:
if (runtime->is_key_pressed(VK_F1) && runtime->is_key_down(VK_MENU)) { // Alt + F1 was pressed my_boolean_state = !my_boolean_state; } if (runtime->is_key_pressed(VK_F2)) { // F2 was pressed }

Please Log in or Create an account to join the conversation.

  • K4sh
  • Topic Author
More
11 months 1 week ago #3 by K4sh Replied by K4sh on topic Bind checkboxes
Thank you again for your help.

I tried your code but it doesn't work for me. Maybe i'm missing something.

Here is my code :
Code:
static void on_overlay_draw(reshade::api::effect_runtime* runtime) {     if (runtime->is_key_pressed(VK_F1) && runtime->is_key_down(VK_MENU))         World_Time_Dilation_fix_enabled = !World_Time_Dilation_fix_enabled;     ImGuiStyle& style = ImGui::GetStyle();     style.ItemSpacing = ImVec2(8 * scale, 8 * scale);     // Spacing between widgets     style.FramePadding = ImVec2(3 * scale, 3 * scale);    // Widgets padding     style.WindowPadding = ImVec2(10 * scale, 10 * scale); // Overlay padding     style.CellPadding = ImVec2(10 * scale, 10 * scale);   // Table cells padding     ImGui::SetNextWindowSize(ImVec2(350 * scale, 150 * scale), ImGuiCond_Once);     ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.84f, 0.12f, 0.51f, 1.0f)); // pink     ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.84f, 0.12f, 0.51f, 1.0f)); // pink     ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.84f, 0.2f, 0.51f, 1.0f)); // pink     ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.8f, 1.f, 1.f, 1.f)); // white     if (ImGui::Button("Like my work ? Consider donation")) ShellExecuteA(NULL, "open", DONATION_URL, NULL, NULL, SW_SHOWNORMAL); // Donation     ImGui::PopStyleColor(4); // Restore color     ImGui::SameLine();     if (ImGui::Button("Fix informations")) popup_Informations = true; // Fix information     ImGui::SameLine();     if (ImGui::Button("View logs")) {         read_log_file("TheCallistoProtocol.log");         show_log_overlay = true; // Fix information     }     if (popup_Informations)     {         ImGui::Begin("Informations", &popup_Informations, ImGuiWindowFlags_AlwaysAutoResize);         ImGui::Text("Version : %s", FIX_VERSION);         ImGui::Text(FIX_INFORMATIONS);         ImGui::End();     }     if (show_log_overlay)     {         ImGui::Begin("Game log", &show_log_overlay, ImGuiWindowFlags_AlwaysAutoResize);         ImGui::TextUnformatted(log_content.c_str());         ImGui::End();     }     ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(10 * scale, 10 * scale));     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);         if (ImGui::CollapsingHeader("Enable fixes", ImGuiTreeNodeFlags_DefaultOpen))             if (ImGui::Checkbox("Fix enabled", &fix_enabled)) {                  if (SetFixEnabled) SetFixEnabled(fix_enabled, false);                 SaveSettings();             }         // 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.35f);                 ImGui::TableSetupColumn("IndFix2", ImGuiTableColumnFlags_WidthStretch, 0.65f);                 ImGui::TableNextRow();                 ImGui::TableSetColumnIndex(0);                 if (ImGui::Checkbox("FOV", &fov_fix_enabled)) {                     if (SetFixesEnabled) SetFixesEnabled(GameFixes::FOV, fov_fix_enabled);                     SaveSettings();                 }                 if (ImGui::Checkbox("Fog", &Fog_fix_enabled)) {                     if (SetFixesEnabled) SetFixesEnabled(GameFixes::Fog, Fog_fix_enabled);                     SaveSettings();                 }                 if (ImGui::Checkbox("Vignetting", &Vignetting_fix_enabled)) {                     if (SetFixesEnabled) SetFixesEnabled(GameFixes::Vignetting, Vignetting_fix_enabled);                     SaveSettings();                 }                 ImGui::TableSetColumnIndex(1);                 if (ImGui::Checkbox("Camera distance", &Camera_fix_enabled)) {                     if (SetFixesEnabled) SetFixesEnabled(GameFixes::Camera, Camera_fix_enabled);                     SaveSettings();                 }                 if (ImGui::IsItemHovered()) {                     ImGui::BeginTooltip();                     ImGui::Text("Experimental fix. Use at your own risk.");                     ImGui::EndTooltip();                 }                 if (ImGui::Checkbox("World time dilation", &World_Time_Dilation_fix_enabled)) {                     if (SetFixesEnabled) SetFixesEnabled(GameFixes::WorldTimeDilation, World_Time_Dilation_fix_enabled);                     SaveSettings();                 }                 if (ImGui::Checkbox("HUD scaling", &HUD_fix_enabled)) {                     if (SetFixesEnabled) SetFixesEnabled(GameFixes::HUD, HUD_fix_enabled);                     SaveSettings();                 }                 if (ImGui::Checkbox("Chromatic aberrations", &CA_fix_enabled)) {                     if (SetFixesEnabled) SetFixesEnabled(GameFixes::ChromaticAberrations, CA_fix_enabled);                     SaveSettings();                 }                 ImGui::EndTable();             }         }         ImGui::EndTable();     }     if (ImGui::BeginTable("SlidersTable", 2, ImGuiTableFlags_SizingStretchSame)) {         ImGui::TableSetupColumn("LeftSliders", ImGuiTableColumnFlags_WidthStretch, 0.5f);         ImGui::TableSetupColumn("RightSliders", ImGuiTableColumnFlags_WidthStretch, 0.5f);         ImGui::TableNextRow();         // Sliders         ImGui::TableSetColumnIndex(0);         if (ImGui::CollapsingHeader("In game additional FOV", ImGuiTreeNodeFlags_DefaultOpen))         {             ImGui::SetNextItemWidth(180 * scale);             if (ImGui::SliderInt("##FOVValue", &worldFOVValue, -20, 50)) {                 if (SetFOV) SetFOV(worldFOVValue);                 SaveSettings();             }         }         if (ImGui::CollapsingHeader("HUD scaling", ImGuiTreeNodeFlags_DefaultOpen))         {             ImGui::SetNextItemWidth(180 * scale);             if (ImGui::SliderInt("##HUDScale", &HUDScaleValue, 0, 40)) {                 if (SetHUDScale) SetHUDScale(HUDScaleValue); SaveSettings();             }         }         ImGui::TableSetColumnIndex(1);         if (ImGui::CollapsingHeader("Camera offset (*)", ImGuiTreeNodeFlags_DefaultOpen))         {             ImGui::SetNextItemWidth(200 * scale);             if (ImGui::SliderInt("##CameraOffset", &cameraOffsetValue, 0, 200)) {                 if (SetCameraOffset) SetCameraOffset(cameraOffsetValue); SaveSettings();             }         }         if (ImGui::IsItemHovered()) {             ImGui::BeginTooltip();             ImGui::Text("Value is in cms.");             ImGui::EndTooltip();         }         if (ImGui::CollapsingHeader("World time dilation", ImGuiTreeNodeFlags_DefaultOpen))         {             ImGui::SetNextItemWidth(180 * scale);             if (ImGui::SliderFloat("##WorldTimeDilationValue", &worldTimeDilationValue, 0, 2, "%.2f")) {                 if (SetWorldTimeDilation) SetWorldTimeDilation(worldTimeDilationValue); SaveSettings();             }         }         if (ImGui::IsItemHovered()) {             ImGui::BeginTooltip();             ImGui::Text("Default value is 1.");             ImGui::EndTooltip();         }         ImGui::EndTable();     }     ImGui::PopStyleVar();     // 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, Out: %.2f, Pawn camera offset: %.2f", infos.FOVIn, infos.FOVOut, infos.CompensatedFOV);         }     } }

Please Log in or Create an account to join the conversation.

  • crosire
More
11 months 6 days ago #4 by crosire Replied by crosire on topic Bind checkboxes
This has to run in a place called every frame, like in a `addon_event::reshade_present` callback. The overlay callback will only be executed when the overlay and your settings are visible and so the shortcut would also only work in that case.

Please Log in or Create an account to join the conversation.

  • K4sh
  • Topic Author
More
11 months 6 days ago - 11 months 6 days ago #5 by K4sh Replied by K4sh on topic Bind checkboxes
Again thank you.
Works like a charm.

Code:
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID) {     switch (ul_reason_for_call)     {         case DLL_PROCESS_ATTACH:             if (!reshade::register_addon(hinstDLL))                 return FALSE;             LoadSettings();             reshade::register_overlay("The Callisto Protocol", &on_overlay_draw);             reshade::register_event<reshade::addon_event::init_effect_runtime>;(                 (reshade::api::effect_runtime* runtime) {                     LoadFixDLL();                 });             reshade::register_event<reshade::addon_event::reshade_present>;(&on_reshade_present);             break;         case DLL_PROCESS_DETACH:             reshade::unregister_event<reshade::addon_event::reshade_present>;(&on_reshade_present);             reshade::unregister_addon(hinstDLL);             break;     }     return TRUE; }
Code:
static void on_reshade_present(reshade::api::effect_runtime* runtime) {     if (runtime->is_key_pressed(VK_F1) && runtime->is_key_down(VK_MENU))         World_Time_Dilation_fix_enabled = !World_Time_Dilation_fix_enabled;     if (prev_WorldTimeDilation != World_Time_Dilation_fix_enabled) {         if (SetFixesEnabled)             SetFixesEnabled(GameFixes::WorldTimeDilation, World_Time_Dilation_fix_enabled);         SaveSettings();         prev_WorldTimeDilation = World_Time_Dilation_fix_enabled;     } }
Last edit: 11 months 6 days ago by K4sh.

Please Log in or Create an account to join the conversation.

  • K4sh
  • Topic Author
More
11 months 1 day ago - 11 months 1 day ago #6 by K4sh Replied by K4sh on topic Bind checkboxes
So now, I have made two tabs where i put my cheats as below
Code:
        if (ImGui::BeginTabItem("Cheats"))         {             ImGui::Checkbox("Time dilation", &Time_Dilation_fix_enabled);             if (ImGui::IsItemHovered()) {                 ImGui::BeginTooltip();                 ImGui::Text("Use ALT + F1 shortcut to de/activate.");                 ImGui::EndTooltip();             }             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);                 if (ImGui::CollapsingHeader("World time dilation", ImGuiTreeNodeFlags_DefaultOpen))                 {                     ImGui::SetNextItemWidth(180 * scale);                     if (ImGui::SliderFloat("##WorldTimeDilationValue", &worldTimeDilationValue, 0, 2, "%.2f")) {                         if (SetWorldTimeDilation) SetWorldTimeDilation(worldTimeDilationValue); SaveSettings();                     }                 }                 if (ImGui::IsItemHovered()) {                     ImGui::BeginTooltip();                     ImGui::Text("Will affect everything in the world.");                     ImGui::Text("Default value is 1.");                     ImGui::EndTooltip();                 }                 ImGui::TableSetColumnIndex(1);                 if (ImGui::CollapsingHeader("AI time dilation", ImGuiTreeNodeFlags_DefaultOpen))                 {                     ImGui::SetNextItemWidth(180 * scale);                     if (ImGui::SliderFloat("##AITimeDilationValue", &AITimeDilationValue, 0, 2, "%.2f")) {                         if (SetAITimeDilation) SetAITimeDilation(AITimeDilationValue); SaveSettings();                     }                 }                 if (ImGui::IsItemHovered()) {                     ImGui::BeginTooltip();                     ImGui::Text("Will affect everything in the world but Jacob.");                     ImGui::Text("Default value is 1.");                     ImGui::EndTooltip();                 }                 ImGui::EndTable();             }             ImGui::EndTabItem();         }


The following code doesn't work anymore (UI visible or not).
It wil not un/tick the checkbox
Code:
static void on_reshade_present(reshade::api::effect_runtime* runtime) {     if (runtime->is_key_pressed(VK_F1) && runtime->is_key_down(VK_MENU))         Time_Dilation_fix_enabled = !Time_Dilation_fix_enabled;     if (prev_TimeDilation != Time_Dilation_fix_enabled) {         if (SetFixesEnabled)             SetFixesEnabled(GameFixes::WorldTimeDilation, Time_Dilation_fix_enabled);         SaveSettings();         prev_TimeDilation = Time_Dilation_fix_enabled;     } }
Last edit: 11 months 1 day ago by K4sh.

Please Log in or Create an account to join the conversation.

  • K4sh
  • Topic Author
More
11 months 1 day ago #7 by K4sh Replied by K4sh on topic Bind checkboxes
Finally, the following code did the trick :
Code:
static void on_reshade_present(reshade::api::effect_runtime* runtime) {     static bool wasTimeDilationInvoked = false;     bool timeDilationInvoked = runtime->is_key_down(VK_MENU) && runtime->is_key_down(VK_F1);     if (timeDilationInvoked && !wasTimeDilationInvoked)         Time_Dilation_fix_enabled = !Time_Dilation_fix_enabled;     wasTimeDilationInvoked = timeDilationInvoked;     if (prev_TimeDilation != Time_Dilation_fix_enabled) {         if (SetFixesEnabled) SetFixesEnabled(GameFixes::WorldTimeDilation, Time_Dilation_fix_enabled); // Apply cheat         SaveSettings();         prev_TimeDilation = Time_Dilation_fix_enabled;     } }

Please Log in or Create an account to join the conversation.