Properly handle input while menu is visible.
* INSERT toggles the menu. Signed-off-by: aixxe <me@aixxe.net>
This commit is contained in:
parent
2f9b1f444d
commit
3ea355bf38
|
@ -11,8 +11,8 @@ enum MouseCodeState_t {
|
||||||
|
|
||||||
class IInputInternal {
|
class IInputInternal {
|
||||||
public:
|
public:
|
||||||
void SetKeyCodeState(KeyCode code, bool pressed) {
|
void SetKeyCodeState(KeyCode code, bool down) {
|
||||||
GetVirtualFunction<void(*)(IInputInternal*, KeyCode, bool)>(this, 83)(this, code, pressed);
|
GetVirtualFunction<void(*)(IInputInternal*, KeyCode, bool)>(this, 83)(this, code, down);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetMouseCodeState(MouseCode code, MouseCodeState_t state) {
|
void SetMouseCodeState(MouseCode code, MouseCodeState_t state) {
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "GUI.h"
|
||||||
|
|
||||||
|
void GUI::DrawFramerateCounter() {
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(10, 10));
|
||||||
|
ImGui::Begin("FPS", nullptr, ImVec2(0, 0), 0.3f, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize);
|
||||||
|
ImGui::Text("FPS: %.2f", ImGui::GetIO().Framerate);
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUI::DrawConfigurationWindow() {
|
||||||
|
ImGui::Begin("cstrike-basehook-linux", nullptr);
|
||||||
|
ImGui::Text("Hello, world!");
|
||||||
|
ImGui::End();
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
#include "GUI.h"
|
||||||
|
|
||||||
|
bool GUI::IsVisible = false;
|
||||||
|
|
||||||
|
void GUI::Render() {
|
||||||
|
// Draw various global components.
|
||||||
|
GUI::DrawFramerateCounter();
|
||||||
|
|
||||||
|
// Draw the actual configuration window.
|
||||||
|
if (GUI::IsVisible)
|
||||||
|
GUI::DrawConfigurationWindow();
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <imgui/imgui.h>
|
||||||
|
#include <imgui/imgui_impl_sdl.h>
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
extern bool IsVisible;
|
||||||
|
|
||||||
|
void DrawFramerateCounter();
|
||||||
|
void DrawConfigurationWindow();
|
||||||
|
|
||||||
|
void Render();
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../Basehook.h"
|
#include "../Basehook.h"
|
||||||
|
#include "../GUI/GUI.h"
|
||||||
|
|
||||||
namespace Hooks {
|
namespace Hooks {
|
||||||
// IBaseClientDLL
|
// IBaseClientDLL
|
||||||
|
|
|
@ -6,6 +6,10 @@ void Hooks::PumpWindowsMessageLoop(ILauncherMgr* thisptr) {
|
||||||
// Get the original function and store it statically.
|
// Get the original function and store it statically.
|
||||||
static PumpWindowsMessageLoop_t oPumpWindowsMessageLoop = sdl_hook->GetOriginalFunction<PumpWindowsMessageLoop_t>(15);
|
static PumpWindowsMessageLoop_t oPumpWindowsMessageLoop = sdl_hook->GetOriginalFunction<PumpWindowsMessageLoop_t>(15);
|
||||||
|
|
||||||
|
// Block game input while the GUI is visible.
|
||||||
|
if (GUI::IsVisible)
|
||||||
|
return;
|
||||||
|
|
||||||
// Call original 'ILauncherMgr::PumpWindowsMessageLoop'.
|
// Call original 'ILauncherMgr::PumpWindowsMessageLoop'.
|
||||||
oPumpWindowsMessageLoop(thisptr);
|
oPumpWindowsMessageLoop(thisptr);
|
||||||
}
|
}
|
|
@ -2,13 +2,17 @@
|
||||||
|
|
||||||
typedef void (*SetKeyCodeState_t) (IInputInternal*, KeyCode, bool);
|
typedef void (*SetKeyCodeState_t) (IInputInternal*, KeyCode, bool);
|
||||||
|
|
||||||
void Hooks::SetKeyCodeState(IInputInternal* thisptr, KeyCode code, bool pressed) {
|
void Hooks::SetKeyCodeState(IInputInternal* thisptr, KeyCode code, bool down) {
|
||||||
// Get the original function and store it statically.
|
// Get the original function and store it statically.
|
||||||
static SetKeyCodeState_t oSetKeyCodeState = inputinternal_hook->GetOriginalFunction<SetKeyCodeState_t>(83);
|
static SetKeyCodeState_t oSetKeyCodeState = inputinternal_hook->GetOriginalFunction<SetKeyCodeState_t>(83);
|
||||||
|
|
||||||
// Print to console every time a key is pressed or released.
|
// Print to console every time a key is pressed or released.
|
||||||
cvar->ConsoleColorPrintf(Color(150, 150, 255, 255), "IInputInternal::SetKeyCodeState - code: %i, pressed: %i\n", code, pressed);
|
cvar->ConsoleColorPrintf(Color(150, 150, 255, 255), "IInputInternal::SetKeyCodeState - code: %i, down: %i\n", code, down);
|
||||||
|
|
||||||
|
// Check if we should open the menu.
|
||||||
|
if (code == KeyCode::KEY_INSERT && down == false)
|
||||||
|
GUI::IsVisible = true;
|
||||||
|
|
||||||
// Call original 'IInputInternal::SetKeyCodeState'.
|
// Call original 'IInputInternal::SetKeyCodeState'.
|
||||||
oSetKeyCodeState(thisptr, code, pressed);
|
oSetKeyCodeState(thisptr, code, down);
|
||||||
}
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
#include "Hooks.h"
|
#include "Hooks.h"
|
||||||
|
#include "../GUI/GUI.h"
|
||||||
#include <imgui/imgui.h>
|
|
||||||
#include <imgui/imgui_impl_sdl.h>
|
|
||||||
|
|
||||||
typedef void (*ShowPixels_t) (ILauncherMgr*, CShowPixelsParams*);
|
typedef void (*ShowPixels_t) (ILauncherMgr*, CShowPixelsParams*);
|
||||||
|
|
||||||
|
@ -30,8 +28,25 @@ void Hooks::ShowPixels(ILauncherMgr* thisptr, CShowPixelsParams* params) {
|
||||||
// Start ImGui rendering.
|
// Start ImGui rendering.
|
||||||
ImGui_ImplSdl_NewFrame(window);
|
ImGui_ImplSdl_NewFrame(window);
|
||||||
|
|
||||||
// Draw some test stuff.
|
// Enable or disable the ImGui cursor depending on the GUI visibility.
|
||||||
ImGui::Text("Hello, world!");
|
ImGui::GetIO().MouseDrawCursor = GUI::IsVisible;
|
||||||
|
ImGui::GetIO().WantCaptureMouse = GUI::IsVisible;
|
||||||
|
ImGui::GetIO().WantCaptureKeyboard = GUI::IsVisible;
|
||||||
|
|
||||||
|
// Handle incoming input while the menu is active.
|
||||||
|
if (GUI::IsVisible) {
|
||||||
|
SDL_Event event = {};
|
||||||
|
|
||||||
|
while (SDL_PollEvent(&event)) {
|
||||||
|
if (event.key.keysym.sym == SDLK_INSERT && event.type == SDL_KEYDOWN)
|
||||||
|
GUI::IsVisible = !GUI::IsVisible;
|
||||||
|
|
||||||
|
ImGui_ImplSdl_ProcessEvent(&event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw GUI components.
|
||||||
|
GUI::Render();
|
||||||
|
|
||||||
// Finish ImGui rendering.
|
// Finish ImGui rendering.
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
Loading…
Reference in New Issue