Merge pull request #21 from PixieCore/master

Added Interface struct and toggled Dev by default.
This commit is contained in:
PixieCore 2021-08-03 17:34:35 +02:00 committed by GitHub
commit 265dd96791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 20 deletions

View File

@ -326,6 +326,13 @@ public:
}
};
struct Interface
{
__int64 (*InterfacePtr)(void);
const char* InterfaceName;
__int64* NextInterfacePtr;
};
/////////////////////////////////////////////////////////////////////////////
// Initialize Game Globals

View File

@ -83,5 +83,7 @@ namespace Hooks
void InstallHooks();
void RemoveHooks();
void ToggleNetHooks();
extern bool bToggledNetHooks;
void ToggleDevCommands();
extern bool bToggledDevFlags;
}

View File

@ -13,6 +13,12 @@ namespace GameGlobals
HostState = reinterpret_cast<CHostState*>(0x141736120); // Get CHostState from memory.
InputSystem = *reinterpret_cast<CInputSystem**>(0x14D40B380); // Get IInputSystem from memory.
Cvar = *reinterpret_cast<CCVar**>(0x14D40B348); // Get CCVar from memory.
// Interface* interfaces = *reinterpret_cast<Interface**>(0x167F4FA48);
// for (Interface* current = interfaces; current; current = reinterpret_cast<Interface*>(current->NextInterfacePtr))
// {
// printf("%s: %p\n", current->InterfaceName, current->InterfacePtr);
// }
IsInitialized = true;
}

View File

@ -3,6 +3,12 @@
bool g_bBlockInput = false;
namespace Hooks
{
bool bToggledDevFlags = false;
bool bToggledNetHooks = false;
}
void Hooks::InstallHooks()
{
///////////////////////////////////////////////////////////////////////////////
@ -58,6 +64,10 @@ void Hooks::InstallHooks()
MH_EnableHook(addr_CHLClient_FrameStageNotify);
MH_EnableHook(addr_CVEngineServer_IsPersistenceDataAvailable);
///////////////////////////////////////////////////////////////////////////////
// Enable ConVar | ConCommand hooks
ToggleDevCommands();
///////////////////////////////////////////////////////////////////////////////
// Enable WinAPI hooks
MH_EnableHook(SetCursorPosPtr);
@ -117,9 +127,7 @@ void Hooks::RemoveHooks()
void Hooks::ToggleNetHooks()
{
static bool g_net = false;
if (!g_net)
if (!bToggledNetHooks)
{
MH_EnableHook(addr_NET_ReceiveDatagram);
MH_EnableHook(addr_NET_SendDatagram);
@ -139,15 +147,12 @@ void Hooks::ToggleNetHooks()
printf("+--------------------------------------------------------+\n");
printf("\n");
}
g_net = !g_net;
bToggledNetHooks = !bToggledNetHooks;
}
void Hooks::ToggleDevCommands()
{
static bool g_dev = false;
if (!g_dev)
if (!bToggledDevFlags)
{
MH_EnableHook(addr_ConVar_IsFlagSet);
MH_EnableHook(addr_ConCommand_IsFlagSet);
@ -156,7 +161,6 @@ void Hooks::ToggleDevCommands()
printf("|>>>>>>>>>>>>>| DEVONLY COMMANDS ACTIVATED |<<<<<<<<<<<<<|\n");
printf("+--------------------------------------------------------+\n");
printf("\n");
}
else
{
@ -168,6 +172,5 @@ void Hooks::ToggleDevCommands()
printf("+--------------------------------------------------------+\n");
printf("\n");
}
g_dev = !g_dev;
bToggledDevFlags = !bToggledDevFlags;
}

View File

@ -17,7 +17,10 @@ bool Hooks::ConVar_IsFlagSet(int** cvar, int flag)
printf(" Verify: %08X\n", flag);
printf("--------------------------------------------------\n");
}
if (flag & 0x80000) { return true; }
if (flag & 0x80000)
{
return true;
}
if (!g_bReturnAllFalse)
{
@ -45,11 +48,15 @@ bool Hooks::ConCommand_IsFlagSet(int* cmd, int flag)
printf(" Verify: %08X\n", flag);
printf("--------------------------------------------------\n");
}
if (flag & 0x80000) { return true; }
if (flag & 0x80000)
{
return true;
}
if (!g_bReturnAllFalse)
{
return(real_flags & flag) != 0;
return (real_flags & flag) != 0;
}
else
{

View File

@ -65,6 +65,8 @@ void CGameConsole::Draw(const char* title)
}
///////////////////////////////////////////////////////////////////////
// If bToggledDevFlags is true, override text color to be green, if its false red.
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();
@ -73,7 +75,12 @@ void CGameConsole::Draw(const char* title)
AddLog("+--------------------------------------------------------+\n");
ProcessCommand("exec autoexec");
}
ImGui::PopStyleColor(); // Pop color override.
ImGui::SameLine();
// Do the same for bToggledNetHooks.
Hooks::bToggledNetHooks ? ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 255, 0, 255)) : ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 0, 0, 255));
if (ImGui::SmallButton("Netchannel Trace"))
{
Hooks::ToggleNetHooks();
@ -82,6 +89,9 @@ void CGameConsole::Draw(const char* title)
AddLog("+--------------------------------------------------------+\n");
ProcessCommand("exec netchan");
}
ImGui::PopStyleColor(); // Pop color override.
///////////////////////////////////////////////////////////////////////
ImGui::SameLine();
if (ImGui::SmallButton("Clear"))
@ -786,17 +796,17 @@ void CCompanion::HostServerSection()
ProcessCommand("reload");
}
if (ImGui::Button("Stop The 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.
}
if (ImGui::Button("Change Level##ServerHost_ChangeLevel", ImVec2(ImGui::GetWindowSize().x, 32)))
{
strncpy_s(GameGlobals::HostState->m_levelName, MyServer.map.c_str(), 64); // Copy new map into hoststate levelname. 64 is size of m_levelname.
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)))
{
ProcessCommand("LeaveMatch"); // Use script callback instead.
GameGlobals::HostState->m_iNextState = HostStates_t::HS_GAME_SHUTDOWN; // Force CHostState::FrameUpdate to shutdown the server for dedicated.
}
}
}