From fe3e37347d1b2724c3950aa1c8fb5652d284130f Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 1 Jun 2017 10:25:13 +0200 Subject: [PATCH] [Scheduler] Distinguish between dedi and client interface --- src/Components/Modules/AntiCheat.cpp | 2 +- src/Components/Modules/Dvar.cpp | 2 +- src/Components/Modules/Exception.cpp | 28 +++++++++++++-------------- src/Components/Modules/FastFiles.cpp | 4 ++-- src/Components/Modules/Maps.cpp | 4 ++-- src/Components/Modules/Materials.cpp | 2 +- src/Components/Modules/Party.cpp | 2 +- src/Components/Modules/QuickPatch.cpp | 14 ++++++-------- src/Components/Modules/Scheduler.cpp | 13 +++++++++---- src/Components/Modules/Scheduler.hpp | 8 ++++---- src/Components/Modules/ServerList.cpp | 2 +- 11 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/Components/Modules/AntiCheat.cpp b/src/Components/Modules/AntiCheat.cpp index 893d6c0d..4d0604e2 100644 --- a/src/Components/Modules/AntiCheat.cpp +++ b/src/Components/Modules/AntiCheat.cpp @@ -582,7 +582,7 @@ namespace Components Utils::Hook(0x60BE9D, AntiCheat::SoundInitStub, HOOK_CALL).install()->quick(); Utils::Hook(0x60BE8E, AntiCheat::SoundInitDriverStub, HOOK_CALL).install()->quick(); Utils::Hook(0x418204, AntiCheat::SoundInitDriverStub, HOOK_CALL).install()->quick(); - if(!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled()) Scheduler::OnFrame(AntiCheat::PerformScan); + Scheduler::OnFrame(AntiCheat::PerformScan, true); // Detect aimbots Utils::Hook(0x426580, AntiCheat::DObjGetWorldTagPosStub, HOOK_JUMP).install()->quick(); diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index 8b585623..165c15ae 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -161,7 +161,7 @@ namespace Components lastValidName = name; Friends::UpdateName(); } - }); + }, true); std::string username = "Unknown Soldier"; diff --git a/src/Components/Modules/Exception.cpp b/src/Components/Modules/Exception.cpp index 2006f730..0da0f9eb 100644 --- a/src/Components/Modules/Exception.cpp +++ b/src/Components/Modules/Exception.cpp @@ -174,23 +174,21 @@ namespace Components #ifdef DEBUG // Display DEBUG branding, so we know we're on a debug build - if (!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled()) { - Scheduler::OnFrame([]() + Scheduler::OnFrame([]() + { + Game::Font* font = Game::R_RegisterFont("fonts/normalFont", 0); + float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + + // Change the color when attaching a debugger + if (IsDebuggerPresent()) { - Game::Font* font = Game::R_RegisterFont("fonts/normalFont", 0); - float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + color[0] = 0.6588f; + color[1] = 1.0000f; + color[2] = 0.0000f; + } - // Change the color when attaching a debugger - if (IsDebuggerPresent()) - { - color[0] = 0.6588f; - color[1] = 1.0000f; - color[2] = 0.0000f; - } - - Game::R_AddCmdDrawText("DEBUG-BUILD", 0x7FFFFFFF, font, 15.0f, 10.0f + Game::R_TextHeight(font), 1.0f, 1.0f, 0.0f, color, Game::ITEM_TEXTSTYLE_SHADOWED); - }); - } + Game::R_AddCmdDrawText("DEBUG-BUILD", 0x7FFFFFFF, font, 15.0f, 10.0f + Game::R_TextHeight(font), 1.0f, 1.0f, 0.0f, color, Game::ITEM_TEXTSTYLE_SHADOWED); + }, true); #endif #if !defined(DEBUG) || defined(FORCE_EXCEPTION_HANDLER) Exception::SetFilterHook.initialize(SetUnhandledExceptionFilter, Exception::SetUnhandledExceptionFilterStub, HOOK_JUMP); diff --git a/src/Components/Modules/FastFiles.cpp b/src/Components/Modules/FastFiles.cpp index a14e3435..8eda7167 100644 --- a/src/Components/Modules/FastFiles.cpp +++ b/src/Components/Modules/FastFiles.cpp @@ -568,7 +568,7 @@ namespace Components { if (FastFiles::Current().empty() || !Dvar::Var("ui_zoneDebug").get()) return; - Game::Font* font = Game::R_RegisterFont("fonts/consoleFont", 0); // Inlining that seems to skip xpos, no idea why xD + Game::Font* font = Game::R_RegisterFont("fonts/consoleFont", 0); float color[4] = { 1.0f, 1.0f, 1.0f, (Game::CL_IsCgameInitialized() ? 0.3f : 1.0f) }; std::uint32_t FFTotalSize = *reinterpret_cast(0x10AA5D8); @@ -585,7 +585,7 @@ namespace Components } Game::R_AddCmdDrawText(Utils::String::VA("Loading FastFile: %s [%0.1f%%]", FastFiles::Current().data(), fastfileLoadProgress), 0x7FFFFFFF, font, 5.0f, static_cast(Renderer::Height() - 5), 1.0f, 1.0f, 0.0f, color, Game::ITEM_TEXTSTYLE_NORMAL); - }); + }, true); Command::Add("loadzone", [] (Command::Params* params) { diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 664393b3..c1f1996e 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -1007,7 +1007,7 @@ namespace Components { Command::Execute("closemenu popup_reconnectingtoparty", false); Command::Execute("reconnect", false); - }, 6s); + }, 6s, true); }); if(Dedicated::IsEnabled()) @@ -1104,7 +1104,7 @@ namespace Components { Game::R_AddCmdDrawText(Utils::String::VA("%d %s", model.second, model.first.data()), 0x7FFFFFFF, font, 15.0f, (height * scale + 1) * (i++ + 1) + 15.0f, scale, scale, 0.0f, color, Game::ITEM_TEXTSTYLE_NORMAL); } - }); + }, true); } Maps::~Maps() diff --git a/src/Components/Modules/Materials.cpp b/src/Components/Modules/Materials.cpp index eb448551..b79c0a26 100644 --- a/src/Components/Modules/Materials.cpp +++ b/src/Components/Modules/Materials.cpp @@ -193,7 +193,7 @@ namespace Components // float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; // // Game::R_AddCmdDrawText("test^==preview_mp_rustzob", 0x7FFFFFFF, font, 500.0f, 150.0f, 1.0f, 1.0f, 0.0f, color, Game::ITEM_TEXTSTYLE_SHADOWED); -// }); +// }, true); } Materials::~Materials() diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index 5fc8252f..aac18715 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -290,7 +290,7 @@ namespace Components Party::ConnectError("Playlist request timed out."); } } - }); + }, true); // Basic info handler Network::Handle("getInfo", [] (Network::Address address, std::string data) diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 27b66b8d..44b8255e 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -656,15 +656,13 @@ namespace Components // Constantly draw the mini console Utils::Hook::Set(0x412A45, 0xEB); - if (!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled()) { - Scheduler::OnFrame([]() + Scheduler::OnFrame([]() + { + if (*reinterpret_cast(0x62E4BAC)) { - if (*reinterpret_cast(0x62E4BAC)) - { - Game::Con_DrawMiniConsole(0, 2, 4, (Game::CL_IsCgameInitialized() ? 1.0f : 0.4f)); - } - }); - } + Game::Con_DrawMiniConsole(0, 2, 4, (Game::CL_IsCgameInitialized() ? 1.0f : 0.4f)); + } + }, true); #else // Remove missing tag message Utils::Hook::Nop(0x4EBF1A, 5); diff --git a/src/Components/Modules/Scheduler.cpp b/src/Components/Modules/Scheduler.cpp index ac6a1c7b..8a81ab97 100644 --- a/src/Components/Modules/Scheduler.cpp +++ b/src/Components/Modules/Scheduler.cpp @@ -10,8 +10,9 @@ namespace Components Utils::Signal Scheduler::FrameOnceSignal; std::vector Scheduler::DelayedSlots; - void Scheduler::Once(Utils::Slot callback) + void Scheduler::Once(Utils::Slot callback, bool clientOnly) { + if (clientOnly && (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled())) return; Scheduler::FrameOnceSignal.connect(callback); } @@ -20,13 +21,15 @@ namespace Components Scheduler::ShutdownSignal.connect(callback); } - void Scheduler::OnFrame(Utils::Slot callback) + void Scheduler::OnFrame(Utils::Slot callback, bool clientOnly) { + if (clientOnly && (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled())) return; Scheduler::FrameSignal.connect(callback); } - void Scheduler::OnReady(Utils::Slot callback) + void Scheduler::OnReady(Utils::Slot callback, bool clientOnly) { + if (clientOnly && (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled())) return; if (Scheduler::ReadyPassed) Scheduler::Once(callback); else Scheduler::ReadySignal.connect(callback); } @@ -57,8 +60,10 @@ namespace Components copy(); } - void Scheduler::OnDelay(Utils::Slot callback, std::chrono::nanoseconds delay) + void Scheduler::OnDelay(Utils::Slot callback, std::chrono::nanoseconds delay, bool clientOnly) { + if (clientOnly && (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled())) return; + Scheduler::DelayedSlot slot; slot.callback = callback; slot.delay = delay; diff --git a/src/Components/Modules/Scheduler.hpp b/src/Components/Modules/Scheduler.hpp index dbf363ae..b77027b8 100644 --- a/src/Components/Modules/Scheduler.hpp +++ b/src/Components/Modules/Scheduler.hpp @@ -11,10 +11,10 @@ namespace Components ~Scheduler(); static void OnShutdown(Utils::Slot callback); - static void OnFrame(Utils::Slot callback); - static void OnReady(Utils::Slot callback); - static void Once(Utils::Slot callback); - static void OnDelay(Utils::Slot callback, std::chrono::nanoseconds delay); + static void OnFrame(Utils::Slot callback, bool clientOnly = false); + static void OnReady(Utils::Slot callback, bool clientOnly = false); + static void Once(Utils::Slot callback, bool clientOnly = false); + static void OnDelay(Utils::Slot callback, std::chrono::nanoseconds delay, bool clientOnly = false); static void FrameHandler(); diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index cbfe1f41..e7d4cf61 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -853,7 +853,7 @@ namespace Components // This is placed here in case the anticheat has been disabled! #if !defined(DEBUG) && !defined(DISABLE_ANTICHEAT) && defined(PROCTECT_PROCESS) - if(!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled()) Scheduler::OnFrame(AntiCheat::ReadIntegrityCheck); + Scheduler::OnFrame(AntiCheat::ReadIntegrityCheck, true); #endif }