mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Split CCompanion and CGameConsole into separate implementations
This commit is contained in:
parent
c329405ae8
commit
540ce8d2b0
@ -1,143 +1,11 @@
|
||||
#pragma once
|
||||
#include "serverlisting.h"
|
||||
#include "gui_utility.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Initialization
|
||||
void PrintDXAddress();
|
||||
void InstallDXHooks();
|
||||
void RemoveDXHooks();
|
||||
void DrawConsole();
|
||||
void DrawBrowser();
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Internals
|
||||
int Stricmp(const char* s1, const char* s2);
|
||||
int Strnicmp(const char* s1, const char* s2, int n);
|
||||
char* Strdup(const char* s);
|
||||
void Strtrim(char* s);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Globals
|
||||
inline ImVector<char*> Items;
|
||||
inline std::string OriginUID = "1010417302770";
|
||||
|
||||
class CGameConsole
|
||||
{
|
||||
private:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
char InputBuf[256] = { 0 };
|
||||
ImVector<const char*> Commands;
|
||||
ImVector<char*> History;
|
||||
int HistoryPos = -1;
|
||||
ImGuiTextFilter Filter;
|
||||
bool AutoScroll = true;
|
||||
bool ScrollToBottom = false;
|
||||
bool ThemeSet = false;
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CGameConsole();
|
||||
~CGameConsole();
|
||||
|
||||
void Draw(const char* title);
|
||||
void ProcessCommand(const char* command_line);
|
||||
void ExecCommand(const char* command_line);
|
||||
int TextEditCallback(ImGuiInputTextCallbackData* data);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// History
|
||||
static int TextEditCallbackStub(ImGuiInputTextCallbackData* data)
|
||||
{
|
||||
CGameConsole* console = (CGameConsole*)data->UserData;
|
||||
return console->TextEditCallback(data);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Utility
|
||||
void ClearLog()
|
||||
{
|
||||
for (int i = 0; i < Items.Size; i++) { free(Items[i]); }
|
||||
Items.clear();
|
||||
}
|
||||
void AddLog(const char* fmt, ...) IM_FMTARGS(2)
|
||||
{
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
|
||||
buf[IM_ARRAYSIZE(buf) - 1] = 0;
|
||||
va_end(args);
|
||||
Items.push_back(Strdup(buf));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Style
|
||||
void SetStyleVar()
|
||||
{
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
ImVec4* colors = style.Colors;
|
||||
|
||||
colors[ImGuiCol_Text] = ImVec4(0.81f, 0.81f, 0.81f, 1.00f);
|
||||
colors[ImGuiCol_TextDisabled] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f);
|
||||
colors[ImGuiCol_WindowBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f);
|
||||
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f);
|
||||
colors[ImGuiCol_Border] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 0.64f);
|
||||
colors[ImGuiCol_FrameBg] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.24f, 0.24f, 0.24f, 1.00f);
|
||||
colors[ImGuiCol_TitleBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgActive] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_MenuBarBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f);
|
||||
colors[ImGuiCol_CheckMark] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
|
||||
colors[ImGuiCol_Button] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_ButtonHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f);
|
||||
colors[ImGuiCol_ButtonActive] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f);
|
||||
colors[ImGuiCol_Header] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f);
|
||||
colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
|
||||
colors[ImGuiCol_Separator] = ImVec4(0.53f, 0.53f, 0.57f, 1.00f);
|
||||
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
|
||||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGrip] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f);
|
||||
colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f);
|
||||
colors[ImGuiCol_TabHovered] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
|
||||
colors[ImGuiCol_TabActive] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
|
||||
|
||||
style.WindowBorderSize = 0.0f;
|
||||
style.FrameBorderSize = 1.0f;
|
||||
style.ChildBorderSize = 1.0f;
|
||||
style.PopupBorderSize = 1.0f;
|
||||
style.TabBorderSize = 1.0f;
|
||||
|
||||
style.WindowRounding = 2.5f;
|
||||
style.FrameRounding = 0.0f;
|
||||
style.ChildRounding = 0.0f;
|
||||
style.PopupRounding = 0.0f;
|
||||
style.TabRounding = 1.0f;
|
||||
style.ScrollbarRounding = 1.0f;
|
||||
|
||||
style.ItemSpacing = ImVec2(4, 4);
|
||||
style.WindowPadding = ImVec2(5, 5);
|
||||
}
|
||||
};
|
||||
|
||||
extern CGameConsole* g_GameConsole;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// ServerBrowser
|
||||
|
||||
class CCompanion
|
||||
{
|
||||
private:
|
||||
@ -148,7 +16,6 @@ public:
|
||||
////////////////////
|
||||
// Enums //
|
||||
////////////////////
|
||||
|
||||
enum class ESection {
|
||||
ServerBrowser,
|
||||
HostServer,
|
125
r5dev/include/CGameConsole.h
Normal file
125
r5dev/include/CGameConsole.h
Normal file
@ -0,0 +1,125 @@
|
||||
#pragma once
|
||||
#include "serverlisting.h"
|
||||
#include "gui_utility.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Initialization
|
||||
void DrawConsole();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Globals
|
||||
inline ImVector<char*> Items;
|
||||
|
||||
class CGameConsole
|
||||
{
|
||||
private:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
char InputBuf[256] = { 0 };
|
||||
ImVector<const char*> Commands;
|
||||
ImVector<char*> History;
|
||||
int HistoryPos = -1;
|
||||
ImGuiTextFilter Filter;
|
||||
bool AutoScroll = true;
|
||||
bool ScrollToBottom = false;
|
||||
bool ThemeSet = false;
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CGameConsole();
|
||||
~CGameConsole();
|
||||
|
||||
void Draw(const char* title);
|
||||
void ProcessCommand(const char* command_line);
|
||||
void ExecCommand(const char* command_line);
|
||||
int TextEditCallback(ImGuiInputTextCallbackData* data);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// History
|
||||
static int TextEditCallbackStub(ImGuiInputTextCallbackData* data)
|
||||
{
|
||||
CGameConsole* console = (CGameConsole*)data->UserData;
|
||||
return console->TextEditCallback(data);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Utility
|
||||
void ClearLog()
|
||||
{
|
||||
for (int i = 0; i < Items.Size; i++) { free(Items[i]); }
|
||||
Items.clear();
|
||||
}
|
||||
void AddLog(const char* fmt, ...) IM_FMTARGS(2)
|
||||
{
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
|
||||
buf[IM_ARRAYSIZE(buf) - 1] = 0;
|
||||
va_end(args);
|
||||
Items.push_back(Strdup(buf));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Style
|
||||
void SetStyleVar()
|
||||
{
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
ImVec4* colors = style.Colors;
|
||||
|
||||
colors[ImGuiCol_Text] = ImVec4(0.81f, 0.81f, 0.81f, 1.00f);
|
||||
colors[ImGuiCol_TextDisabled] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f);
|
||||
colors[ImGuiCol_WindowBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f);
|
||||
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f);
|
||||
colors[ImGuiCol_Border] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 0.64f);
|
||||
colors[ImGuiCol_FrameBg] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.24f, 0.24f, 0.24f, 1.00f);
|
||||
colors[ImGuiCol_TitleBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgActive] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_MenuBarBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f);
|
||||
colors[ImGuiCol_CheckMark] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
|
||||
colors[ImGuiCol_Button] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_ButtonHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f);
|
||||
colors[ImGuiCol_ButtonActive] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f);
|
||||
colors[ImGuiCol_Header] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f);
|
||||
colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
|
||||
colors[ImGuiCol_Separator] = ImVec4(0.53f, 0.53f, 0.57f, 1.00f);
|
||||
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
|
||||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGrip] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f);
|
||||
colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f);
|
||||
colors[ImGuiCol_TabHovered] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
|
||||
colors[ImGuiCol_TabActive] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
|
||||
|
||||
style.WindowBorderSize = 0.0f;
|
||||
style.FrameBorderSize = 1.0f;
|
||||
style.ChildBorderSize = 1.0f;
|
||||
style.PopupBorderSize = 1.0f;
|
||||
style.TabBorderSize = 1.0f;
|
||||
|
||||
style.WindowRounding = 2.5f;
|
||||
style.FrameRounding = 0.0f;
|
||||
style.ChildRounding = 0.0f;
|
||||
style.PopupRounding = 0.0f;
|
||||
style.TabRounding = 1.0f;
|
||||
style.ScrollbarRounding = 1.0f;
|
||||
|
||||
style.ItemSpacing = ImVec2(4, 4);
|
||||
style.WindowPadding = ImVec2(5, 5);
|
||||
}
|
||||
};
|
||||
|
||||
extern CGameConsole* g_GameConsole;
|
6
r5dev/include/gui_utility.h
Normal file
6
r5dev/include/gui_utility.h
Normal file
@ -0,0 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Internals
|
||||
int Stricmp(const char* s1, const char* s2);
|
||||
int Strnicmp(const char* s1, const char* s2, int n);
|
||||
char* Strdup(const char* s);
|
||||
void Strtrim(char* s);
|
@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
#include "patterns.h"
|
||||
#include "structs.h"
|
||||
#include "overlay.h"
|
||||
#include "hooks.h"
|
||||
#include "gameclasses.h"
|
||||
#include "CCompanion.h"
|
||||
#include "CGameConsole.h"
|
||||
|
||||
inline bool g_bDebugLoading = false;
|
||||
inline bool g_bReturnAllFalse = false;
|
||||
|
@ -305,15 +305,17 @@
|
||||
<ClInclude Include="..\shared\include\httplib.h" />
|
||||
<ClInclude Include="..\shared\include\json.hpp" />
|
||||
<ClInclude Include="..\shared\include\utility.h" />
|
||||
<ClInclude Include="include\CCompanion.h" />
|
||||
<ClInclude Include="include\console.h" />
|
||||
<ClInclude Include="include\enums.h" />
|
||||
<ClInclude Include="include\gameclasses.h" />
|
||||
<ClInclude Include="include\gui_utility.h" />
|
||||
<ClInclude Include="include\hooks.h" />
|
||||
<ClInclude Include="include\id3dx.h" />
|
||||
<ClInclude Include="include\imgui_stdlib.h" />
|
||||
<ClInclude Include="include\input.h" />
|
||||
<ClInclude Include="include\opcptc.h" />
|
||||
<ClInclude Include="include\overlay.h" />
|
||||
<ClInclude Include="include\CGameConsole.h" />
|
||||
<ClInclude Include="include\patterns.h" />
|
||||
<ClInclude Include="include\pch.h" />
|
||||
<ClInclude Include="include\r5dev.h" />
|
||||
@ -354,6 +356,7 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\shared\utility.cpp" />
|
||||
<ClCompile Include="src\CCompanion.cpp" />
|
||||
<ClCompile Include="src\console.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">pch.h</PrecompiledHeaderFile>
|
||||
@ -382,11 +385,12 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\gui_utility.cpp" />
|
||||
<ClCompile Include="src\opcptc.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\overlay.cpp">
|
||||
<ClCompile Include="src\CGameConsole.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
|
@ -85,9 +85,6 @@
|
||||
<Filter Include="gui">
|
||||
<UniqueIdentifier>{a40dcf17-855b-4965-b58d-6c7d24edc627}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="gui\src">
|
||||
<UniqueIdentifier>{03d79a58-4706-4ee0-b0ea-6251a2fafada}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="gui\include">
|
||||
<UniqueIdentifier>{89bf5311-5686-4077-9b79-c6306dc1bd91}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@ -100,6 +97,9 @@
|
||||
<Filter Include="r5-sdk\include">
|
||||
<UniqueIdentifier>{0136e8e8-91ef-45c1-8661-476b5c20fc48}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="gui\interface">
|
||||
<UniqueIdentifier>{1979149f-6402-4985-b900-25a91f1168ac}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\dllmain.cpp">
|
||||
@ -156,15 +156,6 @@
|
||||
<ClCompile Include="src\hooks\hooks.cpp">
|
||||
<Filter>hooks\src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\overlay.cpp">
|
||||
<Filter>gui\src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\serverlisting.cpp">
|
||||
<Filter>gui\src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\id3dx.cpp">
|
||||
<Filter>gui\src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\gameclasses.cpp">
|
||||
<Filter>r5-sdk\src</Filter>
|
||||
</ClCompile>
|
||||
@ -180,6 +171,21 @@
|
||||
<ClCompile Include="..\external\imgui\src\imgui_stdlib.cpp">
|
||||
<Filter>shared\libraries\imgui</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\CCompanion.cpp">
|
||||
<Filter>gui\interface</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\CGameConsole.cpp">
|
||||
<Filter>gui\interface</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\serverlisting.cpp">
|
||||
<Filter>gui</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\id3dx.cpp">
|
||||
<Filter>gui</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\gui_utility.cpp">
|
||||
<Filter>gui</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\external\imgui\include\imgui_impl_win32.h">
|
||||
@ -512,7 +518,7 @@
|
||||
<ClInclude Include="include\id3dx.h">
|
||||
<Filter>gui\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\overlay.h">
|
||||
<ClInclude Include="include\CGameConsole.h">
|
||||
<Filter>gui\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\serverlisting.h">
|
||||
@ -545,6 +551,12 @@
|
||||
<ClInclude Include="include\imgui_stdlib.h">
|
||||
<Filter>shared\libraries\imgui\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\CCompanion.h">
|
||||
<Filter>gui\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\gui_utility.h">
|
||||
<Filter>gui\include</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="r5dev.def">
|
||||
|
@ -1,345 +1,19 @@
|
||||
#include "pch.h"
|
||||
#include "overlay.h"
|
||||
#include "hooks.h"
|
||||
#include "id3dx.h"
|
||||
#include "console.h"
|
||||
#include "patterns.h"
|
||||
#include "gameclasses.h"
|
||||
#include "CCompanion.h"
|
||||
|
||||
#define OVERLAY_DEBUG
|
||||
|
||||
CGameConsole* g_GameConsole = nullptr;
|
||||
CCompanion* g_ServerBrowser = nullptr;
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* _overlay.cpp
|
||||
* _ccompanion.cpp
|
||||
*-----------------------------------------------------------------------------*/
|
||||
|
||||
CGameConsole::CGameConsole()
|
||||
{
|
||||
ClearLog();
|
||||
memset(InputBuf, 0, sizeof(InputBuf));
|
||||
|
||||
HistoryPos = -1;
|
||||
AutoScroll = true;
|
||||
ScrollToBottom = false;
|
||||
ThemeSet = false;
|
||||
|
||||
Commands.push_back("HELP");
|
||||
Commands.push_back("HISTORY");
|
||||
Commands.push_back("CLEAR");
|
||||
Commands.push_back("CLASSIFY");
|
||||
|
||||
|
||||
AddLog("[DEBUG] THREAD ID: %ld\n", g_dThreadId);
|
||||
}
|
||||
|
||||
CGameConsole::~CGameConsole()
|
||||
{
|
||||
ClearLog();
|
||||
for (int i = 0; i < History.Size; i++)
|
||||
{
|
||||
free(History[i]);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Draw
|
||||
|
||||
void CGameConsole::Draw(const char* title)
|
||||
{
|
||||
bool copy_to_clipboard = false;
|
||||
|
||||
if (!ThemeSet)
|
||||
{
|
||||
SetStyleVar();
|
||||
ThemeSet = true;
|
||||
}
|
||||
|
||||
//ImGui::ShowStyleEditor();
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(1000, 600), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetWindowPos(ImVec2(-1000, 50), ImGuiCond_FirstUseEver);
|
||||
|
||||
if (!ImGui::Begin(title, NULL)) // Passing a bool only causes problems if you Begin a new window. I would not suggest to use it.
|
||||
{
|
||||
ImGui::End(); return;
|
||||
}
|
||||
|
||||
// Reserve enough left-over height and width for 1 separator + 1 input text
|
||||
const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
|
||||
const float footer_width_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetWindowWidth();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
ImGui::Separator();
|
||||
if (ImGui::BeginPopup("Options"))
|
||||
{
|
||||
ImGui::Checkbox("Auto-scroll", &AutoScroll);
|
||||
if (ImGui::SmallButton("Clear"))
|
||||
{
|
||||
ClearLog();
|
||||
}
|
||||
copy_to_clipboard = ImGui::SmallButton("Copy");
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
if (ImGui::Button("Options"))
|
||||
{
|
||||
ImGui::OpenPopup("Options");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::BeginPopup("Tools"))
|
||||
{
|
||||
Hooks::bToggledDevFlags ? ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 255, 0, 255)) : ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 0, 0, 255));
|
||||
if (ImGui::SmallButton("Developer Mode"))
|
||||
{
|
||||
Hooks::ToggleDevCommands();
|
||||
AddLog("+--------------------------------------------------------+\n");
|
||||
AddLog("|>>>>>>>>>>>>>>| DEVONLY COMMANDS TOGGLED |<<<<<<<<<<<<<<|\n");
|
||||
AddLog("+--------------------------------------------------------+\n");
|
||||
ProcessCommand("exec autoexec");
|
||||
}
|
||||
ImGui::PopStyleColor(); // Pop color override.
|
||||
Hooks::bToggledNetTrace ? ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 255, 0, 255)) : ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 0, 0, 255));
|
||||
if (ImGui::SmallButton("Netchannel Trace"))
|
||||
{
|
||||
Hooks::ToggleNetTrace();
|
||||
AddLog("+--------------------------------------------------------+\n");
|
||||
AddLog("|>>>>>>>>>>>>>>| NETCHANNEL TRACE TOGGLED |<<<<<<<<<<<<<<|\n");
|
||||
AddLog("+--------------------------------------------------------+\n");
|
||||
ProcessCommand("exec netchan");
|
||||
}
|
||||
ImGui::PopStyleColor(); // Pop color override.
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
if (ImGui::Button("Tools"))
|
||||
{
|
||||
ImGui::OpenPopup("Tools");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
Filter.Draw("Filter [\"-incl,-excl\"] [\"error\"]", footer_width_to_reserve - 500);
|
||||
ImGui::Separator();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 4.f, 6.f });
|
||||
if (copy_to_clipboard)
|
||||
{
|
||||
ImGui::LogToClipboard();
|
||||
}
|
||||
for (int i = 0; i < Items.Size; i++)
|
||||
{
|
||||
const char* item = Items[i];
|
||||
if (!Filter.PassFilter(item))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////
|
||||
ImVec4 color;
|
||||
bool has_color = false;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// General
|
||||
if (strstr(item, "[INFO]")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); has_color = true; }
|
||||
if (strstr(item, "[ERROR]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "[DEBUG]")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "[WARNING]")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; }
|
||||
if (strncmp(item, "# ", 2) == 0) { color = ImVec4(1.00f, 0.80f, 0.60f, 1.00f); has_color = true; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Virtual machines
|
||||
if (strstr(item, "Script(S):")) { color = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "Script(C):")) { color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "Script(U):")) { color = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); has_color = true; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Callbacks
|
||||
//if (strstr(item, "CodeCallback_")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Script errors
|
||||
if (strstr(item, ".gnut")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); has_color = true; }
|
||||
if (strstr(item, ".nut")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); has_color = true; }
|
||||
if (strstr(item, "[CLIENT]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "[SERVER]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "[UI]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "SCRIPT ERROR")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "SCRIPT COMPILE")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, ".gnut #")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, ".nut #")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "): -> ")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Script debug
|
||||
if (strstr(item, "CALLSTACK")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; }
|
||||
if (strstr(item, "LOCALS")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; }
|
||||
if (strstr(item, "*FUNCTION")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; }
|
||||
if (strstr(item, "DIAGPRINTS")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; }
|
||||
if (strstr(item, " File : ")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "<><>GRX<><>")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Filters
|
||||
//if (strstr(item, ") -> ")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); has_color = true; }
|
||||
|
||||
if (has_color) { ImGui::PushStyleColor(ImGuiCol_Text, color); }
|
||||
ImGui::TextWrapped(item);
|
||||
if (has_color) { ImGui::PopStyleColor(); }
|
||||
}
|
||||
if (copy_to_clipboard) { ImGui::LogFinish(); }
|
||||
|
||||
if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) { ImGui::SetScrollHereY(1.0f); }
|
||||
ScrollToBottom = false;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::EndChild();
|
||||
ImGui::Separator();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Console
|
||||
bool reclaim_focus = false;
|
||||
ImGui::PushItemWidth(footer_width_to_reserve - 80);
|
||||
if (ImGui::IsWindowAppearing()) { ImGui::SetKeyboardFocusHere(); }
|
||||
ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory;
|
||||
|
||||
if (ImGui::InputText("##input", InputBuf, IM_ARRAYSIZE(InputBuf), input_text_flags, &TextEditCallbackStub, (void*)this))
|
||||
{
|
||||
char* s = InputBuf;
|
||||
const char* replace = "";
|
||||
if (strstr(InputBuf, "`")) { strcpy_s(s, sizeof(replace), replace); }
|
||||
Strtrim(s);
|
||||
if (s[0]) { ProcessCommand(s); }
|
||||
strcpy_s(s, sizeof(replace), replace);
|
||||
reclaim_focus = true;
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Submit"))
|
||||
{
|
||||
char* s = InputBuf;
|
||||
const char* replace = "";
|
||||
if (s[0]) { ProcessCommand(s); }
|
||||
strcpy_s(s, sizeof(replace), replace);
|
||||
reclaim_focus = true;
|
||||
}
|
||||
|
||||
// Auto-focus on window apparition
|
||||
ImGui::SetItemDefaultFocus();
|
||||
|
||||
// Auto focus previous widget
|
||||
if (reclaim_focus)
|
||||
{
|
||||
ImGui::SetKeyboardFocusHere(-1);
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Exec
|
||||
void CGameConsole::ProcessCommand(const char* command_line)
|
||||
{
|
||||
std::thread t(&CGameConsole::ExecCommand, this, command_line);
|
||||
t.detach();
|
||||
|
||||
// HACK: This is to avoid a race condition.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
AddLog("# %s\n", command_line);
|
||||
|
||||
HistoryPos = -1;
|
||||
for (int i = History.Size - 1; i >= 0; i--)
|
||||
{
|
||||
if (Stricmp(History[i], command_line) == 0)
|
||||
{
|
||||
delete History[i];
|
||||
History.erase(History.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
History.push_back(Strdup(command_line));
|
||||
if (Stricmp(command_line, "CLEAR") == 0)
|
||||
{
|
||||
ClearLog();
|
||||
}
|
||||
else if (Stricmp(command_line, "HELP") == 0)
|
||||
{
|
||||
AddLog("Commands:");
|
||||
for (int i = 0; i < Commands.Size; i++)
|
||||
{
|
||||
AddLog("- %s", Commands[i]);
|
||||
}
|
||||
}
|
||||
else if (Stricmp(command_line, "HISTORY") == 0)
|
||||
{
|
||||
int first = History.Size - 10;
|
||||
for (int i = first > 0 ? first : 0; i < History.Size; i++)
|
||||
{
|
||||
AddLog("%3d: %s\n", i, History[i]);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollToBottom = true;
|
||||
}
|
||||
|
||||
void CGameConsole::ExecCommand(const char* command_line)
|
||||
{
|
||||
addr_CommandExecute(NULL, command_line);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Edit
|
||||
int CGameConsole::TextEditCallback(ImGuiInputTextCallbackData* data)
|
||||
{
|
||||
switch (data->EventFlag)
|
||||
{
|
||||
case ImGuiInputTextFlags_CallbackCompletion:
|
||||
{
|
||||
// Locate beginning of current word
|
||||
const char* word_end = data->Buf + data->CursorPos;
|
||||
const char* word_start = word_end;
|
||||
while (word_start > data->Buf)
|
||||
{
|
||||
const char c = word_start[-1];
|
||||
if (c == ' ' || c == '\t' || c == ',' || c == ';')
|
||||
{
|
||||
break;
|
||||
}
|
||||
word_start--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ImGuiInputTextFlags_CallbackHistory:
|
||||
{
|
||||
const int prev_history_pos = HistoryPos;
|
||||
if (data->EventKey == ImGuiKey_UpArrow)
|
||||
{
|
||||
if (HistoryPos == -1) { HistoryPos = History.Size - 1; }
|
||||
else if (HistoryPos > 0) { HistoryPos--; }
|
||||
}
|
||||
else if (data->EventKey == ImGuiKey_DownArrow)
|
||||
{
|
||||
if (HistoryPos != -1)
|
||||
{
|
||||
if (++HistoryPos >= History.Size)
|
||||
{
|
||||
HistoryPos = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prev_history_pos != HistoryPos)
|
||||
{
|
||||
const char* history_str = (HistoryPos >= 0) ? History[HistoryPos] : "";
|
||||
data->DeleteChars(0, data->BufTextLen);
|
||||
data->InsertChars(0, history_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Companion
|
||||
CCompanion::CCompanion()
|
||||
{
|
||||
memset(MatchmakingServerStringBuffer, 0, sizeof(MatchmakingServerStringBuffer));
|
||||
@ -584,7 +258,7 @@ void CCompanion::ServerBrowserSection()
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::Separator();
|
||||
ImGui::InputTextWithHint("##ServerBrowser_ServerConnString", "Enter an ip address or \"localhost\"", ServerConnStringBuffer, IM_ARRAYSIZE(ServerConnStringBuffer));
|
||||
ImGui::InputTextWithHint("##ServerBrowser_ServerConnString", "Enter IP address or \"localhost\"", ServerConnStringBuffer, IM_ARRAYSIZE(ServerConnStringBuffer));
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
@ -601,11 +275,11 @@ void CCompanion::ServerBrowserSection()
|
||||
|
||||
if (ImGui::Button("Private Servers##ServerBrowser_PrivateServersButton", ImVec2(ImGui::GetWindowContentRegionWidth() * (1.f / 3.f / 2.f), 19)))
|
||||
{
|
||||
ImGui::OpenPopup("Connect to a Private Server##PrivateServersConnectModal");
|
||||
ImGui::OpenPopup("Connect to Private Server##PrivateServersConnectModal");
|
||||
}
|
||||
|
||||
bool modalOpen = true;
|
||||
if (ImGui::BeginPopupModal("Connect to a Private Server##PrivateServersConnectModal", &modalOpen))
|
||||
if (ImGui::BeginPopupModal("Connect to Private Server##PrivateServersConnectModal", &modalOpen))
|
||||
{
|
||||
// I *WILL* move this in a separate class
|
||||
|
||||
@ -761,7 +435,7 @@ void CCompanion::HostServerSection()
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::Button("Start The Server##ServerHost_StartServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
|
||||
if (ImGui::Button("Start Server##ServerHost_StartServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
|
||||
{
|
||||
if (!MyServer.name.empty())
|
||||
{
|
||||
@ -810,7 +484,7 @@ void CCompanion::HostServerSection()
|
||||
GameGlobals::HostState->m_iNextState = HostStates_t::HS_CHANGE_LEVEL_MP; // Force CHostState::FrameUpdate to change the level.
|
||||
}
|
||||
|
||||
if (ImGui::Button("Stop The Server##ServerHost_StopServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
|
||||
if (ImGui::Button("Stop Server##ServerHost_StopServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
|
||||
{
|
||||
ProcessCommand("LeaveMatch"); // Use script callback instead.
|
||||
GameGlobals::HostState->m_iNextState = HostStates_t::HS_GAME_SHUTDOWN; // Force CHostState::FrameUpdate to shutdown the server for dedicated.
|
||||
@ -891,61 +565,10 @@ void CCompanion::ConnectToServer(const std::string& connString)
|
||||
g_ServerBrowser->ProcessCommand(cmd.str().c_str());
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
// INTERNALS
|
||||
//#############################################################################
|
||||
|
||||
int Stricmp(const char* s1, const char* s2)
|
||||
{
|
||||
int d;
|
||||
while ((d = toupper(*s2) - toupper(*s1)) == 0 && *s1)
|
||||
{
|
||||
s1++; s2++;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
int Strnicmp(const char* s1, const char* s2, int n)
|
||||
{
|
||||
int d = 0; while (n > 0 && (d = toupper(*s2) - toupper(*s1)) == 0 && *s1)
|
||||
{
|
||||
s1++; s2++; n--;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
char* Strdup(const char* s)
|
||||
{
|
||||
IM_ASSERT(s); size_t len = strlen(s) + 1; void* buf = malloc(len); IM_ASSERT(buf); if (buf != NULL)
|
||||
{
|
||||
return (char*)memcpy(buf, (const void*)s, len);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Strtrim(char* s)
|
||||
{
|
||||
char* str_end = s + strlen(s);
|
||||
|
||||
while (str_end > s && str_end[-1] == ' ')
|
||||
str_end--; *str_end = 0;
|
||||
}
|
||||
|
||||
|
||||
//#############################################################################
|
||||
// ENTRYPOINT
|
||||
//#############################################################################
|
||||
|
||||
void DrawConsole()
|
||||
{
|
||||
static CGameConsole console;
|
||||
static bool AssignPtr = []() {
|
||||
g_GameConsole = &console;
|
||||
return true;
|
||||
} ();
|
||||
console.Draw("Console");
|
||||
}
|
||||
|
||||
void DrawBrowser()
|
||||
{
|
||||
static CCompanion browser;
|
351
r5dev/src/CGameConsole.cpp
Normal file
351
r5dev/src/CGameConsole.cpp
Normal file
@ -0,0 +1,351 @@
|
||||
#include "pch.h"
|
||||
#include "hooks.h"
|
||||
#include "id3dx.h"
|
||||
#include "console.h"
|
||||
#include "patterns.h"
|
||||
#include "gameclasses.h"
|
||||
#include "CGameConsole.h"
|
||||
|
||||
#define OVERLAY_DEBUG
|
||||
|
||||
CGameConsole* g_GameConsole = nullptr;
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* _cgameconsole.cpp
|
||||
*-----------------------------------------------------------------------------*/
|
||||
|
||||
CGameConsole::CGameConsole()
|
||||
{
|
||||
ClearLog();
|
||||
memset(InputBuf, 0, sizeof(InputBuf));
|
||||
|
||||
HistoryPos = -1;
|
||||
AutoScroll = true;
|
||||
ScrollToBottom = false;
|
||||
ThemeSet = false;
|
||||
|
||||
Commands.push_back("HELP");
|
||||
Commands.push_back("HISTORY");
|
||||
Commands.push_back("CLEAR");
|
||||
Commands.push_back("CLASSIFY");
|
||||
|
||||
|
||||
AddLog("[DEBUG] THREAD ID: %ld\n", g_dThreadId);
|
||||
}
|
||||
|
||||
CGameConsole::~CGameConsole()
|
||||
{
|
||||
ClearLog();
|
||||
for (int i = 0; i < History.Size; i++)
|
||||
{
|
||||
free(History[i]);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Draw
|
||||
void CGameConsole::Draw(const char* title)
|
||||
{
|
||||
bool copy_to_clipboard = false;
|
||||
|
||||
if (!ThemeSet)
|
||||
{
|
||||
SetStyleVar();
|
||||
ThemeSet = true;
|
||||
}
|
||||
|
||||
//ImGui::ShowStyleEditor();
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(1000, 600), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetWindowPos(ImVec2(-1000, 50), ImGuiCond_FirstUseEver);
|
||||
|
||||
if (!ImGui::Begin(title, NULL)) // Passing a bool only causes problems if you Begin a new window. I would not suggest to use it.
|
||||
{
|
||||
ImGui::End(); return;
|
||||
}
|
||||
|
||||
// Reserve enough left-over height and width for 1 separator + 1 input text
|
||||
const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
|
||||
const float footer_width_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetWindowWidth();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
ImGui::Separator();
|
||||
if (ImGui::BeginPopup("Options"))
|
||||
{
|
||||
ImGui::Checkbox("Auto-scroll", &AutoScroll);
|
||||
if (ImGui::SmallButton("Clear"))
|
||||
{
|
||||
ClearLog();
|
||||
}
|
||||
copy_to_clipboard = ImGui::SmallButton("Copy");
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
if (ImGui::Button("Options"))
|
||||
{
|
||||
ImGui::OpenPopup("Options");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::BeginPopup("Tools"))
|
||||
{
|
||||
Hooks::bToggledDevFlags ? ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 255, 0, 255)) : ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 0, 0, 255));
|
||||
if (ImGui::SmallButton("Developer Mode"))
|
||||
{
|
||||
Hooks::ToggleDevCommands();
|
||||
AddLog("+--------------------------------------------------------+\n");
|
||||
AddLog("|>>>>>>>>>>>>>>| DEVONLY COMMANDS TOGGLED |<<<<<<<<<<<<<<|\n");
|
||||
AddLog("+--------------------------------------------------------+\n");
|
||||
ProcessCommand("exec autoexec");
|
||||
}
|
||||
ImGui::PopStyleColor(); // Pop color override.
|
||||
Hooks::bToggledNetTrace ? ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 255, 0, 255)) : ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 0, 0, 255));
|
||||
if (ImGui::SmallButton("Netchannel Trace"))
|
||||
{
|
||||
Hooks::ToggleNetTrace();
|
||||
AddLog("+--------------------------------------------------------+\n");
|
||||
AddLog("|>>>>>>>>>>>>>>| NETCHANNEL TRACE TOGGLED |<<<<<<<<<<<<<<|\n");
|
||||
AddLog("+--------------------------------------------------------+\n");
|
||||
ProcessCommand("exec netchan");
|
||||
}
|
||||
ImGui::PopStyleColor(); // Pop color override.
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
if (ImGui::Button("Tools"))
|
||||
{
|
||||
ImGui::OpenPopup("Tools");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
Filter.Draw("Filter [\"-incl,-excl\"] [\"error\"]", footer_width_to_reserve - 500);
|
||||
ImGui::Separator();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 4.f, 6.f });
|
||||
if (copy_to_clipboard)
|
||||
{
|
||||
ImGui::LogToClipboard();
|
||||
}
|
||||
for (int i = 0; i < Items.Size; i++)
|
||||
{
|
||||
const char* item = Items[i];
|
||||
if (!Filter.PassFilter(item))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////
|
||||
ImVec4 color;
|
||||
bool has_color = false;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// General
|
||||
if (strstr(item, "[INFO]")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); has_color = true; }
|
||||
if (strstr(item, "[ERROR]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "[DEBUG]")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "[WARNING]")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; }
|
||||
if (strncmp(item, "# ", 2) == 0) { color = ImVec4(1.00f, 0.80f, 0.60f, 1.00f); has_color = true; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Virtual machines
|
||||
if (strstr(item, "Script(S):")) { color = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "Script(C):")) { color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "Script(U):")) { color = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); has_color = true; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Callbacks
|
||||
//if (strstr(item, "CodeCallback_")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Script errors
|
||||
if (strstr(item, ".gnut")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); has_color = true; }
|
||||
if (strstr(item, ".nut")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); has_color = true; }
|
||||
if (strstr(item, "[CLIENT]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "[SERVER]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "[UI]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "SCRIPT ERROR")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "SCRIPT COMPILE")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, ".gnut #")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, ".nut #")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "): -> ")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Script debug
|
||||
if (strstr(item, "CALLSTACK")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; }
|
||||
if (strstr(item, "LOCALS")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; }
|
||||
if (strstr(item, "*FUNCTION")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; }
|
||||
if (strstr(item, "DIAGPRINTS")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; }
|
||||
if (strstr(item, " File : ")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; }
|
||||
if (strstr(item, "<><>GRX<><>")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Filters
|
||||
//if (strstr(item, ") -> ")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); has_color = true; }
|
||||
|
||||
if (has_color) { ImGui::PushStyleColor(ImGuiCol_Text, color); }
|
||||
ImGui::TextWrapped(item);
|
||||
if (has_color) { ImGui::PopStyleColor(); }
|
||||
}
|
||||
if (copy_to_clipboard) { ImGui::LogFinish(); }
|
||||
|
||||
if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) { ImGui::SetScrollHereY(1.0f); }
|
||||
ScrollToBottom = false;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::EndChild();
|
||||
ImGui::Separator();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Console
|
||||
bool reclaim_focus = false;
|
||||
ImGui::PushItemWidth(footer_width_to_reserve - 80);
|
||||
if (ImGui::IsWindowAppearing()) { ImGui::SetKeyboardFocusHere(); }
|
||||
ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory;
|
||||
|
||||
if (ImGui::InputText("##input", InputBuf, IM_ARRAYSIZE(InputBuf), input_text_flags, &TextEditCallbackStub, (void*)this))
|
||||
{
|
||||
char* s = InputBuf;
|
||||
const char* replace = "";
|
||||
if (strstr(InputBuf, "`")) { strcpy_s(s, sizeof(replace), replace); }
|
||||
Strtrim(s);
|
||||
if (s[0]) { ProcessCommand(s); }
|
||||
strcpy_s(s, sizeof(replace), replace);
|
||||
reclaim_focus = true;
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Submit"))
|
||||
{
|
||||
char* s = InputBuf;
|
||||
const char* replace = "";
|
||||
if (s[0]) { ProcessCommand(s); }
|
||||
strcpy_s(s, sizeof(replace), replace);
|
||||
reclaim_focus = true;
|
||||
}
|
||||
|
||||
// Auto-focus on window apparition
|
||||
ImGui::SetItemDefaultFocus();
|
||||
|
||||
// Auto focus previous widget
|
||||
if (reclaim_focus)
|
||||
{
|
||||
ImGui::SetKeyboardFocusHere(-1);
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Exec
|
||||
void CGameConsole::ProcessCommand(const char* command_line)
|
||||
{
|
||||
std::thread t(&CGameConsole::ExecCommand, this, command_line);
|
||||
t.detach();
|
||||
|
||||
// HACK: This is to avoid a race condition.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
AddLog("# %s\n", command_line);
|
||||
|
||||
HistoryPos = -1;
|
||||
for (int i = History.Size - 1; i >= 0; i--)
|
||||
{
|
||||
if (Stricmp(History[i], command_line) == 0)
|
||||
{
|
||||
delete History[i];
|
||||
History.erase(History.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
History.push_back(Strdup(command_line));
|
||||
if (Stricmp(command_line, "CLEAR") == 0)
|
||||
{
|
||||
ClearLog();
|
||||
}
|
||||
else if (Stricmp(command_line, "HELP") == 0)
|
||||
{
|
||||
AddLog("Commands:");
|
||||
for (int i = 0; i < Commands.Size; i++)
|
||||
{
|
||||
AddLog("- %s", Commands[i]);
|
||||
}
|
||||
}
|
||||
else if (Stricmp(command_line, "HISTORY") == 0)
|
||||
{
|
||||
int first = History.Size - 10;
|
||||
for (int i = first > 0 ? first : 0; i < History.Size; i++)
|
||||
{
|
||||
AddLog("%3d: %s\n", i, History[i]);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollToBottom = true;
|
||||
}
|
||||
|
||||
void CGameConsole::ExecCommand(const char* command_line)
|
||||
{
|
||||
addr_CommandExecute(NULL, command_line);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Edit
|
||||
int CGameConsole::TextEditCallback(ImGuiInputTextCallbackData* data)
|
||||
{
|
||||
switch (data->EventFlag)
|
||||
{
|
||||
case ImGuiInputTextFlags_CallbackCompletion:
|
||||
{
|
||||
// Locate beginning of current word
|
||||
const char* word_end = data->Buf + data->CursorPos;
|
||||
const char* word_start = word_end;
|
||||
while (word_start > data->Buf)
|
||||
{
|
||||
const char c = word_start[-1];
|
||||
if (c == ' ' || c == '\t' || c == ',' || c == ';')
|
||||
{
|
||||
break;
|
||||
}
|
||||
word_start--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ImGuiInputTextFlags_CallbackHistory:
|
||||
{
|
||||
const int prev_history_pos = HistoryPos;
|
||||
if (data->EventKey == ImGuiKey_UpArrow)
|
||||
{
|
||||
if (HistoryPos == -1) { HistoryPos = History.Size - 1; }
|
||||
else if (HistoryPos > 0) { HistoryPos--; }
|
||||
}
|
||||
else if (data->EventKey == ImGuiKey_DownArrow)
|
||||
{
|
||||
if (HistoryPos != -1)
|
||||
{
|
||||
if (++HistoryPos >= History.Size)
|
||||
{
|
||||
HistoryPos = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prev_history_pos != HistoryPos)
|
||||
{
|
||||
const char* history_str = (HistoryPos >= 0) ? History[HistoryPos] : "";
|
||||
data->DeleteChars(0, data->BufTextLen);
|
||||
data->InsertChars(0, history_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
// ENTRYPOINT
|
||||
//#############################################################################
|
||||
|
||||
void DrawConsole()
|
||||
{
|
||||
static CGameConsole console;
|
||||
static bool AssignPtr = []() {
|
||||
g_GameConsole = &console;
|
||||
return true;
|
||||
} ();
|
||||
console.Draw("Console");
|
||||
}
|
43
r5dev/src/gui_utility.cpp
Normal file
43
r5dev/src/gui_utility.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "pch.h"
|
||||
#include "gui_utility.h"
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* _gui_utility.cpp
|
||||
*-----------------------------------------------------------------------------*/
|
||||
|
||||
int Stricmp(const char* s1, const char* s2)
|
||||
{
|
||||
int d;
|
||||
while ((d = toupper(*s2) - toupper(*s1)) == 0 && *s1)
|
||||
{
|
||||
s1++; s2++;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
int Strnicmp(const char* s1, const char* s2, int n)
|
||||
{
|
||||
int d = 0; while (n > 0 && (d = toupper(*s2) - toupper(*s1)) == 0 && *s1)
|
||||
{
|
||||
s1++; s2++; n--;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
char* Strdup(const char* s)
|
||||
{
|
||||
IM_ASSERT(s); size_t len = strlen(s) + 1; void* buf = malloc(len); IM_ASSERT(buf); if (buf != NULL)
|
||||
{
|
||||
return (char*)memcpy(buf, (const void*)s, len);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Strtrim(char* s)
|
||||
{
|
||||
char* str_end = s + strlen(s);
|
||||
|
||||
while (str_end > s && str_end[-1] == ' ')
|
||||
str_end--; *str_end = 0;
|
||||
}
|
@ -3,10 +3,12 @@
|
||||
#include "id3dx.h"
|
||||
#include "hooks.h"
|
||||
#include "console.h"
|
||||
#include "overlay.h"
|
||||
#include "patterns.h"
|
||||
#include "gameclasses.h"
|
||||
|
||||
#include "CCompanion.h"
|
||||
#include "CGameConsole.h"
|
||||
|
||||
|
||||
#pragma comment(lib, "d3d11.lib")
|
||||
|
||||
@ -420,9 +422,9 @@ bool LoadTextureFromByteArray(unsigned char* image_data, const int& image_width,
|
||||
}
|
||||
|
||||
// Create texture
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
ID3D11Texture2D* pTexture = NULL;
|
||||
D3D11_SUBRESOURCE_DATA subResource;
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
ID3D11Texture2D* pTexture = NULL;
|
||||
D3D11_SUBRESOURCE_DATA subResource;
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
||||
|
||||
ZeroMemory(&desc, sizeof(desc));
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "serverlisting.h"
|
||||
#include "overlay.h"
|
||||
#include "CCompanion.h"
|
||||
|
||||
void ServerListing::Select()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user