Fixed several bugs in the GameConsole class

Fixed several bugs in the GameConsole class caused by a single variable that shouldn't be initialized where it was.

Fixed GameConsole glitch on right mouse click event
This commit is contained in:
Amos 2021-06-20 09:04:13 -07:00
parent 7495f1b4fa
commit 5d92c8c226
6 changed files with 74 additions and 66 deletions

View File

@ -9,6 +9,6 @@ void ToggleNetHooks();
/////////////////////////////////////////////////////////////////////////////
// Globals
inline bool g_bDebugLog = false;
inline bool g_bDebugLoading = false;
/////////////////////////////////////////////////////////////////////////////

View File

@ -141,7 +141,7 @@ DWORD __stdcall ProcessConsoleWorker(LPVOID)
///////////////////////////////////////////////////////////////////////////
// Exec toggles
if (sCommand == "1") { ToggleDevCommands(); CommandExecute(NULL, "exec autoexec_dev"); }
if (sCommand == "2") { g_bDebugLog = !g_bDebugLog; continue; }
if (sCommand == "2") { g_bDebugLoading = !g_bDebugLoading; continue; }
///////////////////////////////////////////////////////////////////////////
// Execute the command in the r5 SQVM

View File

@ -88,7 +88,7 @@ bool HSQVM_LoadScript(void* sqvm, const char* script_path, const char* script_na
filepath[i] = '\\';
}
}
if (g_bDebugLog)
if (g_bDebugLoading)
{
printf(" [+] Loading SQVM Script '%s' ...\n", filepath);
}
@ -98,7 +98,7 @@ bool HSQVM_LoadScript(void* sqvm, const char* script_path, const char* script_na
{
return true;
}
if (g_bDebugLog)
if (g_bDebugLoading)
{
printf(" [!] FAILED. Try SP / VPK for '%s'\n", filepath);
}

View File

@ -8,6 +8,7 @@
#include "id3dx.h"
#include "input.h"
#include "enums.h"
#include "console.h"
#include "detours.h"
#include "overlay.h"
#include "patterns.h"
@ -32,6 +33,7 @@ typedef BOOL(WINAPI* IPostMessageW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM l
///////////////////////////////////////////////////////////////////////////////////
extern BOOL g_bShowMenu = false;
static BOOL g_bInitMenu = false;
static BOOL g_bInitialized = false;
static BOOL g_bPresentHooked = false;
@ -61,7 +63,7 @@ LRESULT CALLBACK DXGIMsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
LRESULT CALLBACK HWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK HwndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_KEYDOWN)
{
@ -72,50 +74,49 @@ LRESULT CALLBACK HWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
if (g_bShowMenu)
{//////////////////////////////////////////////////////////////////////////////
ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam);
g_bBlockInput = true;
switch (uMsg)
{
case WM_LBUTTONDOWN:
return 1L;
case WM_LBUTTONUP:
return 1L;
case WM_LBUTTONDBLCLK:
return 1L;
case WM_RBUTTONDOWN:
return 1L;
case WM_RBUTTONUP:
return 1L;
case WM_RBUTTONDBLCLK:
return 1L;
case WM_MBUTTONDOWN:
return 1L;
case WM_MBUTTONUP:
return 1L;
case WM_MBUTTONDBLCLK:
return 1L;
case WM_KEYDOWN:
return 1L;
case WM_KEYUP:
return 1L;
case WM_MOUSEACTIVATE:
return 1L;
case WM_MOUSEHOVER:
return 1L;
case WM_MOUSEHWHEEL:
return 1L;
case WM_MOUSELEAVE:
return 1L;
case WM_MOUSEMOVE:
return 1L;
case WM_MOUSEWHEEL:
return 1L;
case WM_SETCURSOR:
return 1L;
default:
break;
case WM_LBUTTONDOWN:
return 1L;
case WM_LBUTTONUP:
return 1L;
case WM_LBUTTONDBLCLK:
return 1L;
case WM_RBUTTONDOWN:
return 1L;
case WM_RBUTTONUP:
return 1L;
case WM_RBUTTONDBLCLK:
return 1L;
case WM_MBUTTONDOWN:
return 1L;
case WM_MBUTTONUP:
return 1L;
case WM_MBUTTONDBLCLK:
return 1L;
case WM_KEYDOWN:
return 1L;
case WM_KEYUP:
return 1L;
case WM_MOUSEACTIVATE:
return 1L;
case WM_MOUSEHOVER:
return 1L;
case WM_MOUSEHWHEEL:
return 1L;
case WM_MOUSELEAVE:
return 1L;
case WM_MOUSEMOVE:
return 1L;
case WM_MOUSEWHEEL:
return 1L;
case WM_SETCURSOR:
return 1L;
default:
break;
}
}//////////////////////////////////////////////////////////////////////////////
else
@ -169,7 +170,7 @@ void GetPresent()
RegisterClassExA(&wc);
HWND hWnd = CreateWindowA("DX", NULL, WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, NULL, NULL, wc.hInstance, NULL);
DXGI_SWAP_CHAIN_DESC sd;
DXGI_SWAP_CHAIN_DESC sd = { 0 };
D3D_FEATURE_LEVEL nFeatureLevelsSet = D3D_FEATURE_LEVEL_11_0;
D3D_FEATURE_LEVEL nFeatureLevelsSupported;
@ -272,8 +273,21 @@ void DrawImGui()
if (g_bShowMenu)
{
bool bShowMenu = true;
if (!g_bInitMenu)
{
CommandExecute(NULL, "gameui_activate");
g_bInitMenu = true;
}
ShowGameConsole(&bShowMenu);
}
else if(!g_bShowMenu)
{
if (g_bInitMenu)
{
CommandExecute(NULL, "gameui_hide");
g_bInitMenu = false;
}
}
ImGui::EndFrame();
ImGui::Render();
@ -370,7 +384,7 @@ HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT nSyncInterval, UINT n
if (g_oWndProc == nullptr)
{ // Only initialize hWndProc pointer once to avoid stack overflow during ResizeBuffers(..)
g_oWndProc = (WNDPROC)SetWindowLongPtr(g_hGameWindow, GWLP_WNDPROC, (LONG_PTR)HWndProc);
g_oWndProc = (WNDPROC)SetWindowLongPtr(g_hGameWindow, GWLP_WNDPROC, (LONG_PTR)HwndProc);
}
g_bInitialized = true;

View File

@ -22,7 +22,7 @@ static IClipCursor g_oClipCursor = nullptr;
static IShowCursor g_oShowCursor = nullptr;
///////////////////////////////////////////////////////////////////////////////
static POINT g_pLastCursorPos = { 0 };
static POINT g_pLastCursorPos { 0 };
extern BOOL g_bBlockInput = false;
///////////////////////////////////////////////////////////////////////////////

View File

@ -113,15 +113,12 @@ public:
ImGui::SetWindowPos(ImVec2(-1000, 50), ImGuiCond_FirstUseEver);
if (!ImGui::Begin(title, p_open))
{
g_bShowMenu = false;
ImGui::End(); return;
}
if (*p_open == NULL)
{
g_bShowMenu = false;
}
///////////////////////////////////////////////////////////////////////
if (ImGui::SmallButton("Developer mode"))
{
@ -140,7 +137,6 @@ public:
AddLog("+--------------------------------------------------------+\n");
ExecCommand("exec netchan");
}
///////////////////////////////////////////////////////////////////////
ImGui::SameLine();
if (ImGui::SmallButton("Clear"))
@ -159,7 +155,7 @@ public:
ImGui::OpenPopup("Options");
}
ImGui::SameLine();
Filter.Draw("Filter [\"-incl,-excl\"] [\"error\"]", 180);
Filter.Draw("Filter [\"-incl,-excl\"] [\"error\"]", 265);
ImGui::Separator();
// Reserve enough left-over height for 1 separator + 1 input text
@ -167,21 +163,18 @@ public:
///////////////////////////////////////////////////////////////////////
ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 4.f, 6.f });
if (ImGui::BeginPopupContextWindow())
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 4.f, 6.f });
if (copy_to_clipboard)
{
if (ImGui::Selectable("Clear"))
{
ClearLog();
ImGui::EndPopup();
}
}
if (copy_to_clipboard) { ImGui::LogToClipboard(); }
ImGui::LogToClipboard();
}
for (int i = 0; i < Items.Size; i++)
{
const char* item = Items[i];
if (!Filter.PassFilter(item)) { continue; }
if (!Filter.PassFilter(item))
{
continue;
}
///////////////////////////////////////////////////////////////////
ImVec4 color;
bool has_color = false;
@ -249,7 +242,7 @@ public:
colors[ImGuiCol_FrameBgActive] = ImVec4(0.21f, 0.21f, 0.21f, 1.00f);
colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
@ -369,6 +362,7 @@ public:
for (int i = first > 0 ? first : 0; i < History.Size; i++) { AddLog("%3d: %s\n", i, History[i]); }
}
// On command input, we scroll to bottom even if AutoScroll==false
ScrollToBottom = true;
}
@ -386,7 +380,7 @@ public:
{
switch (data->EventFlag)
{
case ImGuiInputTextFlags_CallbackCompletion:
case ImGuiInputTextFlags_CallbackCompletion:
{
// Locate beginning of current word
const char* word_end = data->Buf + data->CursorPos;
@ -399,7 +393,7 @@ public:
}
break;
}
case ImGuiInputTextFlags_CallbackHistory:
case ImGuiInputTextFlags_CallbackHistory:
{
const int prev_history_pos = HistoryPos;
if (data->EventKey == ImGuiKey_UpArrow)