From fe6cb2d737548adf54bace1ba5d33160f377ae3b Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 31 May 2017 15:45:12 +0200 Subject: [PATCH] [Scheduler] Introduce scheduler with 80 compile errors --- src/Components/Loader.hpp | 1 + src/Components/Modules/AntiCheat.cpp | 2 +- src/Components/Modules/AssetHandler.cpp | 2 +- src/Components/Modules/Auth.cpp | 2 +- src/Components/Modules/Bans.cpp | 2 +- src/Components/Modules/Bots.cpp | 6 +- src/Components/Modules/Console.cpp | 2 +- src/Components/Modules/Dedicated.cpp | 34 ++-------- src/Components/Modules/Dedicated.hpp | 12 +--- src/Components/Modules/Download.cpp | 18 +++--- src/Components/Modules/Dvar.cpp | 4 +- src/Components/Modules/Dvar.hpp | 6 +- src/Components/Modules/Exception.cpp | 2 +- src/Components/Modules/FastFiles.cpp | 2 +- src/Components/Modules/Friends.cpp | 4 +- src/Components/Modules/Logger.cpp | 2 +- src/Components/Modules/Materials.cpp | 2 +- src/Components/Modules/Node.cpp | 2 +- src/Components/Modules/QuickPatch.cpp | 67 ++------------------ src/Components/Modules/QuickPatch.hpp | 11 ---- src/Components/Modules/Renderer.cpp | 66 ++------------------ src/Components/Modules/Renderer.hpp | 28 ++------- src/Components/Modules/Scheduler.cpp | 83 +++++++++++++++++++++++++ src/Components/Modules/Scheduler.hpp | 41 ++++++++++++ src/Components/Modules/Script.cpp | 4 +- src/Components/Modules/Script.hpp | 6 +- src/Components/Modules/ServerList.cpp | 4 +- src/Components/Modules/Toast.cpp | 2 +- src/Components/Modules/Window.cpp | 2 +- 29 files changed, 181 insertions(+), 238 deletions(-) create mode 100644 src/Components/Modules/Scheduler.cpp create mode 100644 src/Components/Modules/Scheduler.hpp diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index afb79c17..5887db16 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -64,6 +64,7 @@ namespace Components }; } +#include "Modules/Scheduler.hpp" #include "Modules/Auth.hpp" #include "Modules/Bans.hpp" #include "Modules/Bots.hpp" diff --git a/src/Components/Modules/AntiCheat.cpp b/src/Components/Modules/AntiCheat.cpp index ca136e2f..893d6c0d 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(); - Renderer::OnFrame(AntiCheat::PerformScan); + if(!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled()) Scheduler::OnFrame(AntiCheat::PerformScan); // Detect aimbots Utils::Hook(0x426580, AntiCheat::DObjGetWorldTagPosStub, HOOK_JUMP).install()->quick(); diff --git a/src/Components/Modules/AssetHandler.cpp b/src/Components/Modules/AssetHandler.cpp index c809f553..04bcab1b 100644 --- a/src/Components/Modules/AssetHandler.cpp +++ b/src/Components/Modules/AssetHandler.cpp @@ -418,7 +418,7 @@ namespace Components Utils::Hook(0x5BB6EC, AssetHandler::StoreEmptyAssetStub, HOOK_CALL).install()->quick(); // Log missing empty assets - QuickPatch::OnFrame([] () + Scheduler::OnFrame([] () { if (FastFiles::Ready() && !AssetHandler::EmptyAssets.empty()) { diff --git a/src/Components/Modules/Auth.cpp b/src/Components/Modules/Auth.cpp index 572a80dc..1c661438 100644 --- a/src/Components/Modules/Auth.cpp +++ b/src/Components/Modules/Auth.cpp @@ -404,7 +404,7 @@ namespace Components Auth::LoadKey(true); Steam::SteamUser()->GetSteamID(); - QuickPatch::OnFrame(Auth::Frame); + Scheduler::OnFrame(Auth::Frame); // Register dvar Dvar::Register("sv_securityLevel", 23, 0, 512, Game::dvar_flag::DVAR_FLAG_SERVERINFO, "Security level for GUID certificates (POW)"); diff --git a/src/Components/Modules/Bans.cpp b/src/Components/Modules/Bans.cpp index 17e28b39..a58e9602 100644 --- a/src/Components/Modules/Bans.cpp +++ b/src/Components/Modules/Bans.cpp @@ -194,7 +194,7 @@ namespace Components }); // Verify the list on startup - QuickPatch::Once([] () + Scheduler::Once([] () { Bans::BanList list; Bans::LoadBans(&list); diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index 3ebee741..9292ec0f 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -42,20 +42,20 @@ namespace Components { for (unsigned int i = 0; i < count; ++i) { - Renderer::OnDelay([]() + Scheduler::OnDelay([]() { for (int i = 0; i < 3; ++i) { Game::gentity_t* entRef = Game::SV_AddTestClient(); if (entRef) { - Renderer::OnDelay([entRef]() + Scheduler::OnDelay([entRef]() { Game::Scr_AddString("autoassign"); Game::Scr_AddString("team_marinesopfor"); Game::Scr_Notify(entRef, Game::SL_GetString("menuresponse", 0), 2); - Renderer::OnDelay([entRef]() + Scheduler::OnDelay([entRef]() { Game::Scr_AddString(Utils::String::VA("class%d", Utils::Cryptography::Rand::GenerateInt() % 5)); Game::Scr_AddString("changeclass"); diff --git a/src/Components/Modules/Console.cpp b/src/Components/Modules/Console.cpp index 61d365c9..1a7bbeac 100644 --- a/src/Components/Modules/Console.cpp +++ b/src/Components/Modules/Console.cpp @@ -614,7 +614,7 @@ namespace Components } }, HOOK_CALL).install()->quick(); - QuickPatch::OnFrame([] () + Scheduler::OnFrame([] () { Console::LastRefresh = Game::Sys_Milliseconds(); }); diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index ba017b3f..c9052e7c 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -2,9 +2,6 @@ namespace Components { - Utils::Signal Dedicated::FrameSignal; - Utils::Signal Dedicated::FrameOnceSignal; - SteamID Dedicated::PlayerGuids[18][2]; bool Dedicated::SendChat; @@ -170,7 +167,7 @@ namespace Components partyEnable = Dvar::Var("party_enable").get(); mapname = Dvar::Var("mapname").get(); - QuickPatch::Once([]() + Scheduler::Once([]() { Dvar::Var("party_enable").set(partyEnable); @@ -280,32 +277,12 @@ namespace Components Network::SendCommand(master, "heartbeat", "IW4"); } - void Dedicated::Once(Utils::Slot callback) - { - Dedicated::FrameOnceSignal.connect(callback); - } - - void Dedicated::OnFrame(Utils::Slot callback) - { - Dedicated::FrameSignal.connect(callback); - } - - void Dedicated::FrameHandler() - { - auto copy = Dedicated::FrameSignal; - copy(); - - copy = Dedicated::FrameOnceSignal; - Dedicated::FrameOnceSignal.clear(); - copy(); - } - __declspec(naked) void Dedicated::FrameStub() { __asm { pushad - call Dedicated::FrameHandler + call Scheduler::FrameHandler popad push 5A8E80h @@ -323,7 +300,7 @@ namespace Components if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) // Run zonebuilder as dedi :P { // Make sure all callbacks are handled - Dedicated::OnFrame(Steam::SteamAPI_RunCallbacks); + Scheduler::OnFrame(Steam::SteamAPI_RunCallbacks); Dvar::Register("sv_lanOnly", false, Game::dvar_flag::DVAR_FLAG_NONE, "Don't act as node"); @@ -546,7 +523,7 @@ namespace Components }); } - QuickPatch::OnFrame([]() + Scheduler::OnFrame([]() { if(Dvar::Var("sv_running").get()) { @@ -563,7 +540,6 @@ namespace Components Dedicated::~Dedicated() { - Dedicated::FrameOnceSignal.clear(); - Dedicated::FrameSignal.clear(); + } } diff --git a/src/Components/Modules/Dedicated.hpp b/src/Components/Modules/Dedicated.hpp index 0a3cd54d..c8fb5e07 100644 --- a/src/Components/Modules/Dedicated.hpp +++ b/src/Components/Modules/Dedicated.hpp @@ -5,8 +5,6 @@ namespace Components class Dedicated : public Component { public: - typedef void(Callback)(); - Dedicated(); ~Dedicated(); @@ -16,18 +14,10 @@ namespace Components static void Heartbeat(); - static void OnFrame(Utils::Slot callback); - static void Once(Utils::Slot callback); - private: - static Utils::Signal FrameSignal; - static Utils::Signal FrameOnceSignal; - static bool SendChat; static void MapRotate(); - static void FrameHandler(); - static void FrameStub(); static void InitDedicatedServer(); static void PostInitialization(); @@ -38,6 +28,8 @@ namespace Components static void PreSayStub(); static void PostSayStub(); + static void FrameStub(); + static void TransmitGuids(); static void TimeWrapStub(int code, const char* message); diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index cf0343b8..72a3b583 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -20,7 +20,7 @@ namespace Components { if (Download::CLDownload.running) return; - QuickPatch::Once([]() + Scheduler::Once([]() { Dvar::Var("ui_dl_timeLeft").set(Utils::String::FormatTimeSpan(0)); Dvar::Var("ui_dl_progress").set("(0/0) %"); @@ -119,7 +119,7 @@ namespace Components if (!framePushed) { framePushed = true; - QuickPatch::Once([]() + Scheduler::Once([]() { framePushed = false; Dvar::Var("ui_dl_progress").set(Utils::String::VA("(%d/%d) %d%%", dlIndex, dlSize, dlProgress)); @@ -149,7 +149,7 @@ namespace Components dlDelta = delta; dlTsBytes = fDownload->download->timeStampBytes; - QuickPatch::Once([]() + Scheduler::Once([]() { Dvar::Var("ui_dl_timeLeft").set(Utils::String::FormatTimeSpan(dlTimeLeft)); Dvar::Var("ui_dl_transRate").set(Utils::String::FormatBandwidth(dlTsBytes, dlDelta)); @@ -241,7 +241,7 @@ namespace Components download->thread.detach(); download->clear(); - QuickPatch::Once([]() + Scheduler::Once([]() { Command::Execute("closemenu mod_download_popmenu"); Party::ConnectError("Failed to download the modlist!"); @@ -259,7 +259,7 @@ namespace Components download->thread.detach(); download->clear(); - QuickPatch::Once([]() + Scheduler::Once([]() { Command::Execute("closemenu mod_download_popmenu"); Party::ConnectError("Failed to parse the modlist!"); @@ -285,7 +285,7 @@ namespace Components download->thread.detach(); download->clear(); - QuickPatch::Once([]() + Scheduler::Once([]() { Dvar::Var("partyend_reason").set(mod); mod.clear(); @@ -305,7 +305,7 @@ namespace Components if(download->isMap) { - QuickPatch::Once([]() + Scheduler::Once([]() { Command::Execute("reconnect", false); }); @@ -313,7 +313,7 @@ namespace Components else { // Run this on the main thread - QuickPatch::Once([]() + Scheduler::Once([]() { auto fsGame = Dvar::Var("fs_game"); fsGame.set(mod); @@ -754,7 +754,7 @@ namespace Components }); } - QuickPatch::OnFrame([]() + Scheduler::OnFrame([]() { int workingCount = 0; diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index 1d9b12c5..8ffde0fc 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -2,7 +2,7 @@ namespace Components { - Utils::Signal Dvar::RegistrationSignal; + Utils::Signal Dvar::RegistrationSignal; Dvar::Var::Var(std::string dvarName) : Var() { @@ -131,7 +131,7 @@ namespace Components return Game::Dvar_RegisterInt(name, value, min, max, flag.val, description); } - void Dvar::OnInit(Utils::Slot callback) + void Dvar::OnInit(Utils::Slot callback) { Dvar::RegistrationSignal.connect(callback); } diff --git a/src/Components/Modules/Dvar.hpp b/src/Components/Modules/Dvar.hpp index cbbb87ee..8ead3cf6 100644 --- a/src/Components/Modules/Dvar.hpp +++ b/src/Components/Modules/Dvar.hpp @@ -5,8 +5,6 @@ namespace Components class Dvar : public Component { public: - typedef void(Callback)(); - class Flag { public: @@ -44,14 +42,14 @@ namespace Components Dvar(); ~Dvar(); - static void OnInit(Utils::Slot callback); + static void OnInit(Utils::Slot callback); // Only strings and bools use this type of declaration template static Var Register(const char* name, T value, Flag flag, const char* description); template static Var Register(const char* name, T value, T min, T max, Flag flag, const char* description); private: - static Utils::Signal RegistrationSignal; + static Utils::Signal RegistrationSignal; static Game::dvar_t* RegisterName(const char* name, const char* defaultVal, Game::dvar_flag flag, const char* description); diff --git a/src/Components/Modules/Exception.cpp b/src/Components/Modules/Exception.cpp index 99d33b80..e58a0867 100644 --- a/src/Components/Modules/Exception.cpp +++ b/src/Components/Modules/Exception.cpp @@ -174,7 +174,7 @@ namespace Components #ifdef DEBUG // Display DEBUG branding, so we know we're on a debug build - Renderer::OnFrame([]() + Scheduler::OnFrame([]() { Game::Font* font = Game::R_RegisterFont("fonts/normalFont", 0); float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; diff --git a/src/Components/Modules/FastFiles.cpp b/src/Components/Modules/FastFiles.cpp index dc8ba463..a14e3435 100644 --- a/src/Components/Modules/FastFiles.cpp +++ b/src/Components/Modules/FastFiles.cpp @@ -564,7 +564,7 @@ namespace Components FastFiles::AddZonePath("zone\\patch\\"); FastFiles::AddZonePath("zone\\dlc\\"); - Renderer::OnFrame([] () + Scheduler::OnFrame([] () { if (FastFiles::Current().empty() || !Dvar::Var("ui_zoneDebug").get()) return; diff --git a/src/Components/Modules/Friends.cpp b/src/Components/Modules/Friends.cpp index 08b95a5e..84576cf2 100644 --- a/src/Components/Modules/Friends.cpp +++ b/src/Components/Modules/Friends.cpp @@ -597,7 +597,7 @@ namespace Components } }); - QuickPatch::OnFrame([]() + Scheduler::OnFrame([]() { static Utils::Time::Interval timeInterval; static Utils::Time::Interval sortInterval; @@ -658,7 +658,7 @@ namespace Components } }); - QuickPatch::Once([]() + Scheduler::Once([]() { if (Steam::Proxy::SteamFriends) { diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index da0f3a1f..592c7805 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -247,7 +247,7 @@ namespace Components Logger::PipeOutput(nullptr); - QuickPatch::OnFrame(Logger::Frame); + Scheduler::OnFrame(Logger::Frame); Utils::Hook(0x4B0218, Logger::GameLogStub, HOOK_CALL).install()->quick(); Utils::Hook(Game::Com_PrintMessage, Logger::PrintMessageStub, HOOK_JUMP).install()->quick(); diff --git a/src/Components/Modules/Materials.cpp b/src/Components/Modules/Materials.cpp index f8eb3ab4..eb448551 100644 --- a/src/Components/Modules/Materials.cpp +++ b/src/Components/Modules/Materials.cpp @@ -187,7 +187,7 @@ namespace Components } #endif -// Renderer::OnFrame([] () +// Scheduler::OnFrame([] () // { // Game::Font* font = Game::R_RegisterFont("fonts/normalFont"); // float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index 7c192e91..bcd7e145 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -895,7 +895,7 @@ namespace Components }); // Install frame handlers - QuickPatch::OnFrame(Node::FrameHandler); + Scheduler::OnFrame(Node::FrameHandler); Network::OnStart([] () { diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index a132bdcc..3643389b 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -3,9 +3,6 @@ namespace Components { int QuickPatch::FrameTime = 0; - bool QuickPatch::ReadyPassed = false; - Utils::Signal QuickPatch::ReadySignal; - Utils::Signal QuickPatch::ShutdownSignal; int64_t* QuickPatch::GetStatsID() { @@ -13,58 +10,6 @@ namespace Components return &id; } - void QuickPatch::OnReady(Utils::Slot callback) - { - if(QuickPatch::ReadyPassed) QuickPatch::Once(callback); - else QuickPatch::ReadySignal.connect(callback); - } - - void QuickPatch::ReadyHandler() - { - if (!FastFiles::Ready()) QuickPatch::Once(QuickPatch::ReadyHandler); - else - { - QuickPatch::ReadyPassed = true; - QuickPatch::ReadySignal(); - QuickPatch::ReadySignal.clear(); - } - } - - void QuickPatch::OnShutdown(Utils::Slot callback) - { - QuickPatch::ShutdownSignal.connect(callback); - } - - void QuickPatch::ShutdownStub(int num) - { - QuickPatch::ShutdownSignal(); - Utils::Hook::Call(0x46B370)(num); - } - - void QuickPatch::OnFrame(Utils::Slot callback) - { - if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) - { - Dedicated::OnFrame(callback); - } - else - { - Renderer::OnFrame(callback); - } - } - - void QuickPatch::Once(Utils::Slot callback) - { - if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) - { - Dedicated::Once(callback); - } - else - { - Renderer::Once(callback); - } - } - void QuickPatch::UnlockStats() { if (Dedicated::IsEnabled()) return; @@ -196,17 +141,14 @@ namespace Components QuickPatch::QuickPatch() { - QuickPatch::ReadyPassed = false; - QuickPatch::Once(QuickPatch::ReadyHandler); - QuickPatch::FrameTime = 0; - QuickPatch::OnFrame([]() + Scheduler::OnFrame([]() { QuickPatch::FrameTime = Game::Sys_Milliseconds(); }); // Make sure preDestroy is called when the game shuts down - QuickPatch::OnShutdown(Loader::PreDestroy); + Scheduler::OnShutdown(Loader::PreDestroy); // protocol version (workaround for hacks) Utils::Hook::Set(0x4FB501, PROTOCOL); @@ -671,7 +613,7 @@ namespace Components Dvar::Register("r_drawAabbTrees", false, Game::DVAR_FLAG_USERCREATED, "Draw aabb trees"); }); - Renderer::OnFrame([]() + Scheduler::OnFrame([]() { if (!Game::CL_IsCgameInitialized() || !Dvar::Var("r_drawAabbTrees").get()) return; @@ -735,8 +677,7 @@ namespace Components QuickPatch::~QuickPatch() { - QuickPatch::ReadySignal.clear(); - QuickPatch::ShutdownSignal.clear(); + } bool QuickPatch::unitTest() diff --git a/src/Components/Modules/QuickPatch.hpp b/src/Components/Modules/QuickPatch.hpp index 60c44584..097fb7ce 100644 --- a/src/Components/Modules/QuickPatch.hpp +++ b/src/Components/Modules/QuickPatch.hpp @@ -5,31 +5,20 @@ namespace Components class QuickPatch : public Component { public: - typedef void(Callback)(); - QuickPatch(); ~QuickPatch(); bool unitTest() override; static void UnlockStats(); - 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 int GetFrameTime() { return FrameTime; } private: static int FrameTime; - static bool ReadyPassed; - static Utils::Signal ReadySignal; - static Utils::Signal ShutdownSignal; static int64_t* GetStatsID(); static void ShutdownStub(int num); - static void ReadyHandler(); - static void SelectStringTableEntryInDvarStub(); static int MsgReadBitsCompressCheckSV(const char *from, char *to, int size); diff --git a/src/Components/Modules/Renderer.cpp b/src/Components/Modules/Renderer.cpp index 83e278d6..37bfd0c3 100644 --- a/src/Components/Modules/Renderer.cpp +++ b/src/Components/Modules/Renderer.cpp @@ -2,21 +2,17 @@ namespace Components { - Utils::Signal Renderer::FrameSignal; - Utils::Signal Renderer::FrameOnceSignal; Utils::Signal Renderer::BackendFrameSignal; - Utils::Signal Renderer::EndRecoverDeviceSignal; - Utils::Signal Renderer::BeginRecoverDeviceSignal; - - std::vector Renderer::DelayedSlots; + Utils::Signal Renderer::EndRecoverDeviceSignal; + Utils::Signal Renderer::BeginRecoverDeviceSignal; __declspec(naked) void Renderer::FrameStub() { __asm { pushad - call Renderer::FrameHandler + call Scheduler::FrameHandler popad push 5AC950h @@ -24,16 +20,6 @@ namespace Components } } - void Renderer::FrameHandler() - { - Renderer::DelaySignal(); - Renderer::FrameSignal(); - - Utils::Signal copy(Renderer::FrameOnceSignal); - Renderer::FrameOnceSignal.clear(); - copy(); - } - __declspec(naked) void Renderer::BackendFrameStub() { __asm @@ -60,61 +46,21 @@ namespace Components } } - void Renderer::Once(Utils::Slot callback) - { - if (Dedicated::IsEnabled()) return; - Renderer::FrameOnceSignal.connect(callback); - } - - void Renderer::OnFrame(Utils::Slot callback) - { - if (Dedicated::IsEnabled()) return; - Renderer::FrameSignal.connect(callback); - } - void Renderer::OnBackendFrame(Utils::Slot callback) { Renderer::BackendFrameSignal.connect(callback); } - void Renderer::OnDeviceRecoveryEnd(Utils::Slot callback) + void Renderer::OnDeviceRecoveryEnd(Utils::Slot callback) { Renderer::EndRecoverDeviceSignal.connect(callback); } - void Renderer::OnDeviceRecoveryBegin(Utils::Slot callback) + void Renderer::OnDeviceRecoveryBegin(Utils::Slot callback) { Renderer::BeginRecoverDeviceSignal.connect(callback); } - void Renderer::OnDelay(Utils::Slot callback, std::chrono::nanoseconds delay) - { - Renderer::DelayedSlot slot; - slot.callback = callback; - slot.delay = delay; - - Renderer::DelayedSlots.push_back(slot); - } - - void Renderer::DelaySignal() - { - Utils::Signal signal; - - for(auto i = Renderer::DelayedSlots.begin(); i != Renderer::DelayedSlots.end();) - { - if(i->interval.elapsed(i->delay)) - { - signal.connect(i->callback); - i = Renderer::DelayedSlots.erase(i); - continue; - } - - ++i; - } - - signal(); - } - int Renderer::Width() { return Utils::Hook::Get(0x66E1C68); @@ -178,8 +124,6 @@ namespace Components Renderer::~Renderer() { Renderer::BackendFrameSignal.clear(); - Renderer::FrameOnceSignal.clear(); - Renderer::FrameSignal.clear(); Renderer::EndRecoverDeviceSignal.clear(); Renderer::BeginRecoverDeviceSignal.clear(); diff --git a/src/Components/Modules/Renderer.hpp b/src/Components/Modules/Renderer.hpp index 23673599..25c428a4 100644 --- a/src/Components/Modules/Renderer.hpp +++ b/src/Components/Modules/Renderer.hpp @@ -5,7 +5,6 @@ namespace Components class Renderer : public Component { public: - typedef void(Callback)(); typedef void(BackendCallback)(IDirect3DDevice9*); Renderer(); @@ -14,39 +13,20 @@ namespace Components static int Width(); static int Height(); - static void Once(Utils::Slot callback); - static void OnFrame(Utils::Slot callback); static void OnBackendFrame(Utils::Slot callback); - static void OnDelay(Utils::Slot callback, std::chrono::nanoseconds delay); + static void OnDeviceRecoveryEnd(Utils::Slot callback); + static void OnDeviceRecoveryBegin(Utils::Slot callback); - static void OnDeviceRecoveryEnd(Utils::Slot callback); - static void OnDeviceRecoveryBegin(Utils::Slot callback); private: - class DelayedSlot - { - public: - std::chrono::nanoseconds delay; - Utils::Time::Interval interval; - Utils::Slot callback; - }; - static void FrameStub(); - static void FrameHandler(); static void BackendFrameStub(); static void BackendFrameHandler(); - static void DelaySignal(); - - static Utils::Signal FrameSignal; - static Utils::Signal FrameOnceSignal; - - static Utils::Signal EndRecoverDeviceSignal; - static Utils::Signal BeginRecoverDeviceSignal; + static Utils::Signal EndRecoverDeviceSignal; + static Utils::Signal BeginRecoverDeviceSignal; static Utils::Signal BackendFrameSignal; - - static std::vector DelayedSlots; }; } diff --git a/src/Components/Modules/Scheduler.cpp b/src/Components/Modules/Scheduler.cpp new file mode 100644 index 00000000..9626fed8 --- /dev/null +++ b/src/Components/Modules/Scheduler.cpp @@ -0,0 +1,83 @@ +#include "STDInclude.hpp" + +namespace Components +{ + bool Scheduler::ReadyPassed = false; + Utils::Signal Scheduler::ReadySignal; + Utils::Signal Scheduler::ShutdownSignal; + + Utils::Signal Scheduler::FrameSignal; + Utils::Signal Scheduler::FrameOnceSignal; + std::vector Scheduler::DelayedSlots; + + void Scheduler::Once(Utils::Slot callback) + { + Scheduler::FrameOnceSignal.connect(callback); + } + + void Scheduler::OnFrame(Utils::Slot callback) + { + Scheduler::FrameSignal.connect(callback); + } + + void Scheduler::ReadyHandler() + { + if (!FastFiles::Ready()) Scheduler::Once(Scheduler::ReadyHandler); + else + { + Scheduler::ReadyPassed = true; + Scheduler::ReadySignal(); + Scheduler::ReadySignal.clear(); + } + } + + void Scheduler::FrameHandler() + { + Scheduler::DelaySignal(); + Scheduler::FrameSignal(); + + Utils::Signal copy(Scheduler::FrameOnceSignal); + Scheduler::FrameOnceSignal.clear(); + copy(); + } + + void Scheduler::OnDelay(Utils::Slot callback, std::chrono::nanoseconds delay) + { + Scheduler::DelayedSlot slot; + slot.callback = callback; + slot.delay = delay; + + Scheduler::DelayedSlots.push_back(slot); + } + + void Scheduler::DelaySignal() + { + Utils::Signal signal; + + for (auto i = Scheduler::DelayedSlots.begin(); i != Scheduler::DelayedSlots.end();) + { + if (i->interval.elapsed(i->delay)) + { + signal.connect(i->callback); + i = Scheduler::DelayedSlots.erase(i); + continue; + } + + ++i; + } + + signal(); + } + + Scheduler::Scheduler() + { + Scheduler::ReadyPassed = false; + Scheduler::Once(Scheduler::ReadyHandler); + } + + Scheduler::~Scheduler() + { + Scheduler::FrameOnceSignal.clear(); + Scheduler::FrameSignal.clear(); + } +} diff --git a/src/Components/Modules/Scheduler.hpp b/src/Components/Modules/Scheduler.hpp new file mode 100644 index 00000000..475d8f68 --- /dev/null +++ b/src/Components/Modules/Scheduler.hpp @@ -0,0 +1,41 @@ +#pragma once + +namespace Components +{ + class Scheduler : public Component + { + public: + typedef void(Callback)(); + + Scheduler(); + ~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 FrameHandler(); + + private: + class DelayedSlot + { + public: + std::chrono::nanoseconds delay; + Utils::Time::Interval interval; + Utils::Slot callback; + }; + + static Utils::Signal FrameSignal; + static Utils::Signal FrameOnceSignal; + static std::vector DelayedSlots; + + static bool ReadyPassed; + static Utils::Signal ReadySignal; + static Utils::Signal ShutdownSignal; + + static void ReadyHandler(); + static void DelaySignal(); + }; +} diff --git a/src/Components/Modules/Script.cpp b/src/Components/Modules/Script.cpp index c83af63f..82c93984 100644 --- a/src/Components/Modules/Script.cpp +++ b/src/Components/Modules/Script.cpp @@ -8,7 +8,7 @@ namespace Components std::vector Script::ScriptNameStack; unsigned short Script::FunctionName; - Utils::Signal Script::VMShutdownSignal; + Utils::Signal Script::VMShutdownSignal; void Script::FunctionError() { @@ -247,7 +247,7 @@ namespace Components Script::ScriptFunctions.push_back({ name, function, isDev }); } - void Script::OnVMShutdown(Utils::Slot callback) + void Script::OnVMShutdown(Utils::Slot callback) { Script::VMShutdownSignal.connect(callback); } diff --git a/src/Components/Modules/Script.hpp b/src/Components/Modules/Script.hpp index 14bc5119..5e6e8fc9 100644 --- a/src/Components/Modules/Script.hpp +++ b/src/Components/Modules/Script.hpp @@ -6,8 +6,6 @@ namespace Components class Script : public Component { public: - typedef void(Callback)(); - class Function { public: @@ -29,7 +27,7 @@ namespace Components static int LoadScriptAndLabel(std::string script, std::string label); static void AddFunction(std::string name, Game::scr_function_t function, bool isDev = false); - static void OnVMShutdown(Utils::Slot callback); + static void OnVMShutdown(Utils::Slot callback); private: static std::string ScriptName; @@ -38,7 +36,7 @@ namespace Components static std::vector ScriptNameStack; static unsigned short FunctionName; - static Utils::Signal VMShutdownSignal; + static Utils::Signal VMShutdownSignal; static void CompileError(unsigned int offset, const char* message, ...); static void PrintSourcePos(const char* filename, unsigned int offset); diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index a3168e47..6c3c6b64 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -849,11 +849,11 @@ namespace Components UIScript::AddOwnerDraw(253, ServerList::UpdateGameType); // Add frame callback - Renderer::OnFrame(ServerList::Frame); + Scheduler::OnFrame(ServerList::Frame); // This is placed here in case the anticheat has been disabled! #if !defined(DEBUG) && !defined(DISABLE_ANTICHEAT) && defined(PROCTECT_PROCESS) - Renderer::OnFrame(AntiCheat::ReadIntegrityCheck); + Scheduler::OnFrame(AntiCheat::ReadIntegrityCheck); #endif } diff --git a/src/Components/Modules/Toast.cpp b/src/Components/Modules/Toast.cpp index c4037af0..d38c1ab4 100644 --- a/src/Components/Modules/Toast.cpp +++ b/src/Components/Modules/Toast.cpp @@ -159,7 +159,7 @@ namespace Components QuickPatch::OnReady([]() { - Renderer::OnFrame(Toast::Handler); + Scheduler::OnFrame(Toast::Handler); }); Command::Add("testtoast", [] (Command::Params*) diff --git a/src/Components/Modules/Window.cpp b/src/Components/Modules/Window.cpp index d35eadfa..57d6ac3b 100644 --- a/src/Components/Modules/Window.cpp +++ b/src/Components/Modules/Window.cpp @@ -140,7 +140,7 @@ namespace Components Utils::Hook(0x48E5D3, Window::DrawCursorStub, HOOK_CALL).install()->quick(); // Draw the cursor if necessary - Renderer::OnFrame([] () + Scheduler::OnFrame([] () { if (Window::NativeCursor.get() && IsWindow(Window::MainWindow) && GetForegroundWindow() == Window::MainWindow && Window::IsCursorWithin(Window::MainWindow)) {