[Scheduler] Introduce scheduler with 80 compile errors

This commit is contained in:
momo5502 2017-05-31 15:45:12 +02:00
parent c0575fdc50
commit fe6cb2d737
29 changed files with 181 additions and 238 deletions

View File

@ -64,6 +64,7 @@ namespace Components
}; };
} }
#include "Modules/Scheduler.hpp"
#include "Modules/Auth.hpp" #include "Modules/Auth.hpp"
#include "Modules/Bans.hpp" #include "Modules/Bans.hpp"
#include "Modules/Bots.hpp" #include "Modules/Bots.hpp"

View File

@ -582,7 +582,7 @@ namespace Components
Utils::Hook(0x60BE9D, AntiCheat::SoundInitStub, HOOK_CALL).install()->quick(); Utils::Hook(0x60BE9D, AntiCheat::SoundInitStub, HOOK_CALL).install()->quick();
Utils::Hook(0x60BE8E, AntiCheat::SoundInitDriverStub, HOOK_CALL).install()->quick(); Utils::Hook(0x60BE8E, AntiCheat::SoundInitDriverStub, HOOK_CALL).install()->quick();
Utils::Hook(0x418204, 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 // Detect aimbots
Utils::Hook(0x426580, AntiCheat::DObjGetWorldTagPosStub, HOOK_JUMP).install()->quick(); Utils::Hook(0x426580, AntiCheat::DObjGetWorldTagPosStub, HOOK_JUMP).install()->quick();

View File

@ -418,7 +418,7 @@ namespace Components
Utils::Hook(0x5BB6EC, AssetHandler::StoreEmptyAssetStub, HOOK_CALL).install()->quick(); Utils::Hook(0x5BB6EC, AssetHandler::StoreEmptyAssetStub, HOOK_CALL).install()->quick();
// Log missing empty assets // Log missing empty assets
QuickPatch::OnFrame([] () Scheduler::OnFrame([] ()
{ {
if (FastFiles::Ready() && !AssetHandler::EmptyAssets.empty()) if (FastFiles::Ready() && !AssetHandler::EmptyAssets.empty())
{ {

View File

@ -404,7 +404,7 @@ namespace Components
Auth::LoadKey(true); Auth::LoadKey(true);
Steam::SteamUser()->GetSteamID(); Steam::SteamUser()->GetSteamID();
QuickPatch::OnFrame(Auth::Frame); Scheduler::OnFrame(Auth::Frame);
// Register dvar // Register dvar
Dvar::Register<int>("sv_securityLevel", 23, 0, 512, Game::dvar_flag::DVAR_FLAG_SERVERINFO, "Security level for GUID certificates (POW)"); Dvar::Register<int>("sv_securityLevel", 23, 0, 512, Game::dvar_flag::DVAR_FLAG_SERVERINFO, "Security level for GUID certificates (POW)");

View File

@ -194,7 +194,7 @@ namespace Components
}); });
// Verify the list on startup // Verify the list on startup
QuickPatch::Once([] () Scheduler::Once([] ()
{ {
Bans::BanList list; Bans::BanList list;
Bans::LoadBans(&list); Bans::LoadBans(&list);

View File

@ -42,20 +42,20 @@ namespace Components
{ {
for (unsigned int i = 0; i < count; ++i) for (unsigned int i = 0; i < count; ++i)
{ {
Renderer::OnDelay([]() Scheduler::OnDelay([]()
{ {
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
{ {
Game::gentity_t* entRef = Game::SV_AddTestClient(); Game::gentity_t* entRef = Game::SV_AddTestClient();
if (entRef) if (entRef)
{ {
Renderer::OnDelay([entRef]() Scheduler::OnDelay([entRef]()
{ {
Game::Scr_AddString("autoassign"); Game::Scr_AddString("autoassign");
Game::Scr_AddString("team_marinesopfor"); Game::Scr_AddString("team_marinesopfor");
Game::Scr_Notify(entRef, Game::SL_GetString("menuresponse", 0), 2); 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(Utils::String::VA("class%d", Utils::Cryptography::Rand::GenerateInt() % 5));
Game::Scr_AddString("changeclass"); Game::Scr_AddString("changeclass");

View File

@ -614,7 +614,7 @@ namespace Components
} }
}, HOOK_CALL).install()->quick(); }, HOOK_CALL).install()->quick();
QuickPatch::OnFrame([] () Scheduler::OnFrame([] ()
{ {
Console::LastRefresh = Game::Sys_Milliseconds(); Console::LastRefresh = Game::Sys_Milliseconds();
}); });

View File

@ -2,9 +2,6 @@
namespace Components namespace Components
{ {
Utils::Signal<Dedicated::Callback> Dedicated::FrameSignal;
Utils::Signal<Dedicated::Callback> Dedicated::FrameOnceSignal;
SteamID Dedicated::PlayerGuids[18][2]; SteamID Dedicated::PlayerGuids[18][2];
bool Dedicated::SendChat; bool Dedicated::SendChat;
@ -170,7 +167,7 @@ namespace Components
partyEnable = Dvar::Var("party_enable").get<bool>(); partyEnable = Dvar::Var("party_enable").get<bool>();
mapname = Dvar::Var("mapname").get<std::string>(); mapname = Dvar::Var("mapname").get<std::string>();
QuickPatch::Once([]() Scheduler::Once([]()
{ {
Dvar::Var("party_enable").set(partyEnable); Dvar::Var("party_enable").set(partyEnable);
@ -280,32 +277,12 @@ namespace Components
Network::SendCommand(master, "heartbeat", "IW4"); Network::SendCommand(master, "heartbeat", "IW4");
} }
void Dedicated::Once(Utils::Slot<Dedicated::Callback> callback)
{
Dedicated::FrameOnceSignal.connect(callback);
}
void Dedicated::OnFrame(Utils::Slot<Dedicated::Callback> 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() __declspec(naked) void Dedicated::FrameStub()
{ {
__asm __asm
{ {
pushad pushad
call Dedicated::FrameHandler call Scheduler::FrameHandler
popad popad
push 5A8E80h push 5A8E80h
@ -323,7 +300,7 @@ namespace Components
if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) // Run zonebuilder as dedi :P if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) // Run zonebuilder as dedi :P
{ {
// Make sure all callbacks are handled // Make sure all callbacks are handled
Dedicated::OnFrame(Steam::SteamAPI_RunCallbacks); Scheduler::OnFrame(Steam::SteamAPI_RunCallbacks);
Dvar::Register<bool>("sv_lanOnly", false, Game::dvar_flag::DVAR_FLAG_NONE, "Don't act as node"); Dvar::Register<bool>("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<bool>()) if(Dvar::Var("sv_running").get<bool>())
{ {
@ -563,7 +540,6 @@ namespace Components
Dedicated::~Dedicated() Dedicated::~Dedicated()
{ {
Dedicated::FrameOnceSignal.clear();
Dedicated::FrameSignal.clear();
} }
} }

View File

@ -5,8 +5,6 @@ namespace Components
class Dedicated : public Component class Dedicated : public Component
{ {
public: public:
typedef void(Callback)();
Dedicated(); Dedicated();
~Dedicated(); ~Dedicated();
@ -16,18 +14,10 @@ namespace Components
static void Heartbeat(); static void Heartbeat();
static void OnFrame(Utils::Slot<Callback> callback);
static void Once(Utils::Slot<Callback> callback);
private: private:
static Utils::Signal<Callback> FrameSignal;
static Utils::Signal<Callback> FrameOnceSignal;
static bool SendChat; static bool SendChat;
static void MapRotate(); static void MapRotate();
static void FrameHandler();
static void FrameStub();
static void InitDedicatedServer(); static void InitDedicatedServer();
static void PostInitialization(); static void PostInitialization();
@ -38,6 +28,8 @@ namespace Components
static void PreSayStub(); static void PreSayStub();
static void PostSayStub(); static void PostSayStub();
static void FrameStub();
static void TransmitGuids(); static void TransmitGuids();
static void TimeWrapStub(int code, const char* message); static void TimeWrapStub(int code, const char* message);

View File

@ -20,7 +20,7 @@ namespace Components
{ {
if (Download::CLDownload.running) return; if (Download::CLDownload.running) return;
QuickPatch::Once([]() Scheduler::Once([]()
{ {
Dvar::Var("ui_dl_timeLeft").set(Utils::String::FormatTimeSpan(0)); Dvar::Var("ui_dl_timeLeft").set(Utils::String::FormatTimeSpan(0));
Dvar::Var("ui_dl_progress").set("(0/0) %"); Dvar::Var("ui_dl_progress").set("(0/0) %");
@ -119,7 +119,7 @@ namespace Components
if (!framePushed) if (!framePushed)
{ {
framePushed = true; framePushed = true;
QuickPatch::Once([]() Scheduler::Once([]()
{ {
framePushed = false; framePushed = false;
Dvar::Var("ui_dl_progress").set(Utils::String::VA("(%d/%d) %d%%", dlIndex, dlSize, dlProgress)); Dvar::Var("ui_dl_progress").set(Utils::String::VA("(%d/%d) %d%%", dlIndex, dlSize, dlProgress));
@ -149,7 +149,7 @@ namespace Components
dlDelta = delta; dlDelta = delta;
dlTsBytes = fDownload->download->timeStampBytes; dlTsBytes = fDownload->download->timeStampBytes;
QuickPatch::Once([]() Scheduler::Once([]()
{ {
Dvar::Var("ui_dl_timeLeft").set(Utils::String::FormatTimeSpan(dlTimeLeft)); Dvar::Var("ui_dl_timeLeft").set(Utils::String::FormatTimeSpan(dlTimeLeft));
Dvar::Var("ui_dl_transRate").set(Utils::String::FormatBandwidth(dlTsBytes, dlDelta)); Dvar::Var("ui_dl_transRate").set(Utils::String::FormatBandwidth(dlTsBytes, dlDelta));
@ -241,7 +241,7 @@ namespace Components
download->thread.detach(); download->thread.detach();
download->clear(); download->clear();
QuickPatch::Once([]() Scheduler::Once([]()
{ {
Command::Execute("closemenu mod_download_popmenu"); Command::Execute("closemenu mod_download_popmenu");
Party::ConnectError("Failed to download the modlist!"); Party::ConnectError("Failed to download the modlist!");
@ -259,7 +259,7 @@ namespace Components
download->thread.detach(); download->thread.detach();
download->clear(); download->clear();
QuickPatch::Once([]() Scheduler::Once([]()
{ {
Command::Execute("closemenu mod_download_popmenu"); Command::Execute("closemenu mod_download_popmenu");
Party::ConnectError("Failed to parse the modlist!"); Party::ConnectError("Failed to parse the modlist!");
@ -285,7 +285,7 @@ namespace Components
download->thread.detach(); download->thread.detach();
download->clear(); download->clear();
QuickPatch::Once([]() Scheduler::Once([]()
{ {
Dvar::Var("partyend_reason").set(mod); Dvar::Var("partyend_reason").set(mod);
mod.clear(); mod.clear();
@ -305,7 +305,7 @@ namespace Components
if(download->isMap) if(download->isMap)
{ {
QuickPatch::Once([]() Scheduler::Once([]()
{ {
Command::Execute("reconnect", false); Command::Execute("reconnect", false);
}); });
@ -313,7 +313,7 @@ namespace Components
else else
{ {
// Run this on the main thread // Run this on the main thread
QuickPatch::Once([]() Scheduler::Once([]()
{ {
auto fsGame = Dvar::Var("fs_game"); auto fsGame = Dvar::Var("fs_game");
fsGame.set(mod); fsGame.set(mod);
@ -754,7 +754,7 @@ namespace Components
}); });
} }
QuickPatch::OnFrame([]() Scheduler::OnFrame([]()
{ {
int workingCount = 0; int workingCount = 0;

View File

@ -2,7 +2,7 @@
namespace Components namespace Components
{ {
Utils::Signal<Dvar::Callback> Dvar::RegistrationSignal; Utils::Signal<Scheduler::Callback> Dvar::RegistrationSignal;
Dvar::Var::Var(std::string dvarName) : Var() Dvar::Var::Var(std::string dvarName) : Var()
{ {
@ -131,7 +131,7 @@ namespace Components
return Game::Dvar_RegisterInt(name, value, min, max, flag.val, description); return Game::Dvar_RegisterInt(name, value, min, max, flag.val, description);
} }
void Dvar::OnInit(Utils::Slot<Dvar::Callback> callback) void Dvar::OnInit(Utils::Slot<Scheduler::Callback> callback)
{ {
Dvar::RegistrationSignal.connect(callback); Dvar::RegistrationSignal.connect(callback);
} }

View File

@ -5,8 +5,6 @@ namespace Components
class Dvar : public Component class Dvar : public Component
{ {
public: public:
typedef void(Callback)();
class Flag class Flag
{ {
public: public:
@ -44,14 +42,14 @@ namespace Components
Dvar(); Dvar();
~Dvar(); ~Dvar();
static void OnInit(Utils::Slot<Callback> callback); static void OnInit(Utils::Slot<Scheduler::Callback> callback);
// Only strings and bools use this type of declaration // Only strings and bools use this type of declaration
template<typename T> static Var Register(const char* name, T value, Flag flag, const char* description); template<typename T> static Var Register(const char* name, T value, Flag flag, const char* description);
template<typename T> static Var Register(const char* name, T value, T min, T max, Flag flag, const char* description); template<typename T> static Var Register(const char* name, T value, T min, T max, Flag flag, const char* description);
private: private:
static Utils::Signal<Callback> RegistrationSignal; static Utils::Signal<Scheduler::Callback> RegistrationSignal;
static Game::dvar_t* RegisterName(const char* name, const char* defaultVal, Game::dvar_flag flag, const char* description); static Game::dvar_t* RegisterName(const char* name, const char* defaultVal, Game::dvar_flag flag, const char* description);

View File

@ -174,7 +174,7 @@ namespace Components
#ifdef DEBUG #ifdef DEBUG
// Display DEBUG branding, so we know we're on a debug build // 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); Game::Font* font = Game::R_RegisterFont("fonts/normalFont", 0);
float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };

View File

@ -564,7 +564,7 @@ namespace Components
FastFiles::AddZonePath("zone\\patch\\"); FastFiles::AddZonePath("zone\\patch\\");
FastFiles::AddZonePath("zone\\dlc\\"); FastFiles::AddZonePath("zone\\dlc\\");
Renderer::OnFrame([] () Scheduler::OnFrame([] ()
{ {
if (FastFiles::Current().empty() || !Dvar::Var("ui_zoneDebug").get<bool>()) return; if (FastFiles::Current().empty() || !Dvar::Var("ui_zoneDebug").get<bool>()) return;

View File

@ -597,7 +597,7 @@ namespace Components
} }
}); });
QuickPatch::OnFrame([]() Scheduler::OnFrame([]()
{ {
static Utils::Time::Interval timeInterval; static Utils::Time::Interval timeInterval;
static Utils::Time::Interval sortInterval; static Utils::Time::Interval sortInterval;
@ -658,7 +658,7 @@ namespace Components
} }
}); });
QuickPatch::Once([]() Scheduler::Once([]()
{ {
if (Steam::Proxy::SteamFriends) if (Steam::Proxy::SteamFriends)
{ {

View File

@ -247,7 +247,7 @@ namespace Components
Logger::PipeOutput(nullptr); Logger::PipeOutput(nullptr);
QuickPatch::OnFrame(Logger::Frame); Scheduler::OnFrame(Logger::Frame);
Utils::Hook(0x4B0218, Logger::GameLogStub, HOOK_CALL).install()->quick(); Utils::Hook(0x4B0218, Logger::GameLogStub, HOOK_CALL).install()->quick();
Utils::Hook(Game::Com_PrintMessage, Logger::PrintMessageStub, HOOK_JUMP).install()->quick(); Utils::Hook(Game::Com_PrintMessage, Logger::PrintMessageStub, HOOK_JUMP).install()->quick();

View File

@ -187,7 +187,7 @@ namespace Components
} }
#endif #endif
// Renderer::OnFrame([] () // Scheduler::OnFrame([] ()
// { // {
// Game::Font* font = Game::R_RegisterFont("fonts/normalFont"); // Game::Font* font = Game::R_RegisterFont("fonts/normalFont");
// float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; // float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };

View File

@ -895,7 +895,7 @@ namespace Components
}); });
// Install frame handlers // Install frame handlers
QuickPatch::OnFrame(Node::FrameHandler); Scheduler::OnFrame(Node::FrameHandler);
Network::OnStart([] () Network::OnStart([] ()
{ {

View File

@ -3,9 +3,6 @@
namespace Components namespace Components
{ {
int QuickPatch::FrameTime = 0; int QuickPatch::FrameTime = 0;
bool QuickPatch::ReadyPassed = false;
Utils::Signal<QuickPatch::Callback> QuickPatch::ReadySignal;
Utils::Signal<QuickPatch::Callback> QuickPatch::ShutdownSignal;
int64_t* QuickPatch::GetStatsID() int64_t* QuickPatch::GetStatsID()
{ {
@ -13,58 +10,6 @@ namespace Components
return &id; return &id;
} }
void QuickPatch::OnReady(Utils::Slot<QuickPatch::Callback> 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<QuickPatch::Callback> callback)
{
QuickPatch::ShutdownSignal.connect(callback);
}
void QuickPatch::ShutdownStub(int num)
{
QuickPatch::ShutdownSignal();
Utils::Hook::Call<void(int)>(0x46B370)(num);
}
void QuickPatch::OnFrame(Utils::Slot<QuickPatch::Callback> callback)
{
if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled())
{
Dedicated::OnFrame(callback);
}
else
{
Renderer::OnFrame(callback);
}
}
void QuickPatch::Once(Utils::Slot<QuickPatch::Callback> callback)
{
if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled())
{
Dedicated::Once(callback);
}
else
{
Renderer::Once(callback);
}
}
void QuickPatch::UnlockStats() void QuickPatch::UnlockStats()
{ {
if (Dedicated::IsEnabled()) return; if (Dedicated::IsEnabled()) return;
@ -196,17 +141,14 @@ namespace Components
QuickPatch::QuickPatch() QuickPatch::QuickPatch()
{ {
QuickPatch::ReadyPassed = false;
QuickPatch::Once(QuickPatch::ReadyHandler);
QuickPatch::FrameTime = 0; QuickPatch::FrameTime = 0;
QuickPatch::OnFrame([]() Scheduler::OnFrame([]()
{ {
QuickPatch::FrameTime = Game::Sys_Milliseconds(); QuickPatch::FrameTime = Game::Sys_Milliseconds();
}); });
// Make sure preDestroy is called when the game shuts down // Make sure preDestroy is called when the game shuts down
QuickPatch::OnShutdown(Loader::PreDestroy); Scheduler::OnShutdown(Loader::PreDestroy);
// protocol version (workaround for hacks) // protocol version (workaround for hacks)
Utils::Hook::Set<int>(0x4FB501, PROTOCOL); Utils::Hook::Set<int>(0x4FB501, PROTOCOL);
@ -671,7 +613,7 @@ namespace Components
Dvar::Register<bool>("r_drawAabbTrees", false, Game::DVAR_FLAG_USERCREATED, "Draw aabb trees"); Dvar::Register<bool>("r_drawAabbTrees", false, Game::DVAR_FLAG_USERCREATED, "Draw aabb trees");
}); });
Renderer::OnFrame([]() Scheduler::OnFrame([]()
{ {
if (!Game::CL_IsCgameInitialized() || !Dvar::Var("r_drawAabbTrees").get<bool>()) return; if (!Game::CL_IsCgameInitialized() || !Dvar::Var("r_drawAabbTrees").get<bool>()) return;
@ -735,8 +677,7 @@ namespace Components
QuickPatch::~QuickPatch() QuickPatch::~QuickPatch()
{ {
QuickPatch::ReadySignal.clear();
QuickPatch::ShutdownSignal.clear();
} }
bool QuickPatch::unitTest() bool QuickPatch::unitTest()

View File

@ -5,31 +5,20 @@ namespace Components
class QuickPatch : public Component class QuickPatch : public Component
{ {
public: public:
typedef void(Callback)();
QuickPatch(); QuickPatch();
~QuickPatch(); ~QuickPatch();
bool unitTest() override; bool unitTest() override;
static void UnlockStats(); static void UnlockStats();
static void OnShutdown(Utils::Slot<Callback> callback);
static void OnFrame(Utils::Slot<Callback> callback);
static void OnReady(Utils::Slot<Callback> callback);
static void Once(Utils::Slot<Callback> callback);
static int GetFrameTime() { return FrameTime; } static int GetFrameTime() { return FrameTime; }
private: private:
static int FrameTime; static int FrameTime;
static bool ReadyPassed;
static Utils::Signal<Callback> ReadySignal;
static Utils::Signal<Callback> ShutdownSignal;
static int64_t* GetStatsID(); static int64_t* GetStatsID();
static void ShutdownStub(int num); static void ShutdownStub(int num);
static void ReadyHandler();
static void SelectStringTableEntryInDvarStub(); static void SelectStringTableEntryInDvarStub();
static int MsgReadBitsCompressCheckSV(const char *from, char *to, int size); static int MsgReadBitsCompressCheckSV(const char *from, char *to, int size);

View File

@ -2,21 +2,17 @@
namespace Components namespace Components
{ {
Utils::Signal<Renderer::Callback> Renderer::FrameSignal;
Utils::Signal<Renderer::Callback> Renderer::FrameOnceSignal;
Utils::Signal<Renderer::BackendCallback> Renderer::BackendFrameSignal; Utils::Signal<Renderer::BackendCallback> Renderer::BackendFrameSignal;
Utils::Signal<Renderer::Callback> Renderer::EndRecoverDeviceSignal; Utils::Signal<Scheduler::Callback> Renderer::EndRecoverDeviceSignal;
Utils::Signal<Renderer::Callback> Renderer::BeginRecoverDeviceSignal; Utils::Signal<Scheduler::Callback> Renderer::BeginRecoverDeviceSignal;
std::vector<Renderer::DelayedSlot> Renderer::DelayedSlots;
__declspec(naked) void Renderer::FrameStub() __declspec(naked) void Renderer::FrameStub()
{ {
__asm __asm
{ {
pushad pushad
call Renderer::FrameHandler call Scheduler::FrameHandler
popad popad
push 5AC950h push 5AC950h
@ -24,16 +20,6 @@ namespace Components
} }
} }
void Renderer::FrameHandler()
{
Renderer::DelaySignal();
Renderer::FrameSignal();
Utils::Signal<Renderer::Callback> copy(Renderer::FrameOnceSignal);
Renderer::FrameOnceSignal.clear();
copy();
}
__declspec(naked) void Renderer::BackendFrameStub() __declspec(naked) void Renderer::BackendFrameStub()
{ {
__asm __asm
@ -60,61 +46,21 @@ namespace Components
} }
} }
void Renderer::Once(Utils::Slot<Renderer::Callback> callback)
{
if (Dedicated::IsEnabled()) return;
Renderer::FrameOnceSignal.connect(callback);
}
void Renderer::OnFrame(Utils::Slot<Renderer::Callback> callback)
{
if (Dedicated::IsEnabled()) return;
Renderer::FrameSignal.connect(callback);
}
void Renderer::OnBackendFrame(Utils::Slot<Renderer::BackendCallback> callback) void Renderer::OnBackendFrame(Utils::Slot<Renderer::BackendCallback> callback)
{ {
Renderer::BackendFrameSignal.connect(callback); Renderer::BackendFrameSignal.connect(callback);
} }
void Renderer::OnDeviceRecoveryEnd(Utils::Slot<Renderer::Callback> callback) void Renderer::OnDeviceRecoveryEnd(Utils::Slot<Scheduler::Callback> callback)
{ {
Renderer::EndRecoverDeviceSignal.connect(callback); Renderer::EndRecoverDeviceSignal.connect(callback);
} }
void Renderer::OnDeviceRecoveryBegin(Utils::Slot<Renderer::Callback> callback) void Renderer::OnDeviceRecoveryBegin(Utils::Slot<Scheduler::Callback> callback)
{ {
Renderer::BeginRecoverDeviceSignal.connect(callback); Renderer::BeginRecoverDeviceSignal.connect(callback);
} }
void Renderer::OnDelay(Utils::Slot<Renderer::Callback> callback, std::chrono::nanoseconds delay)
{
Renderer::DelayedSlot slot;
slot.callback = callback;
slot.delay = delay;
Renderer::DelayedSlots.push_back(slot);
}
void Renderer::DelaySignal()
{
Utils::Signal<Renderer::Callback> 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() int Renderer::Width()
{ {
return Utils::Hook::Get<int>(0x66E1C68); return Utils::Hook::Get<int>(0x66E1C68);
@ -178,8 +124,6 @@ namespace Components
Renderer::~Renderer() Renderer::~Renderer()
{ {
Renderer::BackendFrameSignal.clear(); Renderer::BackendFrameSignal.clear();
Renderer::FrameOnceSignal.clear();
Renderer::FrameSignal.clear();
Renderer::EndRecoverDeviceSignal.clear(); Renderer::EndRecoverDeviceSignal.clear();
Renderer::BeginRecoverDeviceSignal.clear(); Renderer::BeginRecoverDeviceSignal.clear();

View File

@ -5,7 +5,6 @@ namespace Components
class Renderer : public Component class Renderer : public Component
{ {
public: public:
typedef void(Callback)();
typedef void(BackendCallback)(IDirect3DDevice9*); typedef void(BackendCallback)(IDirect3DDevice9*);
Renderer(); Renderer();
@ -14,39 +13,20 @@ namespace Components
static int Width(); static int Width();
static int Height(); static int Height();
static void Once(Utils::Slot<Callback> callback);
static void OnFrame(Utils::Slot<Callback> callback);
static void OnBackendFrame(Utils::Slot<BackendCallback> callback); static void OnBackendFrame(Utils::Slot<BackendCallback> callback);
static void OnDelay(Utils::Slot<Callback> callback, std::chrono::nanoseconds delay); static void OnDeviceRecoveryEnd(Utils::Slot<Scheduler::Callback> callback);
static void OnDeviceRecoveryBegin(Utils::Slot<Scheduler::Callback> callback);
static void OnDeviceRecoveryEnd(Utils::Slot<Callback> callback);
static void OnDeviceRecoveryBegin(Utils::Slot<Callback> callback);
private: private:
class DelayedSlot
{
public:
std::chrono::nanoseconds delay;
Utils::Time::Interval interval;
Utils::Slot<Callback> callback;
};
static void FrameStub(); static void FrameStub();
static void FrameHandler();
static void BackendFrameStub(); static void BackendFrameStub();
static void BackendFrameHandler(); static void BackendFrameHandler();
static void DelaySignal(); static Utils::Signal<Scheduler::Callback> EndRecoverDeviceSignal;
static Utils::Signal<Scheduler::Callback> BeginRecoverDeviceSignal;
static Utils::Signal<Callback> FrameSignal;
static Utils::Signal<Callback> FrameOnceSignal;
static Utils::Signal<Callback> EndRecoverDeviceSignal;
static Utils::Signal<Callback> BeginRecoverDeviceSignal;
static Utils::Signal<BackendCallback> BackendFrameSignal; static Utils::Signal<BackendCallback> BackendFrameSignal;
static std::vector<DelayedSlot> DelayedSlots;
}; };
} }

View File

@ -0,0 +1,83 @@
#include "STDInclude.hpp"
namespace Components
{
bool Scheduler::ReadyPassed = false;
Utils::Signal<Scheduler::Callback> Scheduler::ReadySignal;
Utils::Signal<Scheduler::Callback> Scheduler::ShutdownSignal;
Utils::Signal<Scheduler::Callback> Scheduler::FrameSignal;
Utils::Signal<Scheduler::Callback> Scheduler::FrameOnceSignal;
std::vector<Scheduler::DelayedSlot> Scheduler::DelayedSlots;
void Scheduler::Once(Utils::Slot<Scheduler::Callback> callback)
{
Scheduler::FrameOnceSignal.connect(callback);
}
void Scheduler::OnFrame(Utils::Slot<Scheduler::Callback> 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<Scheduler::Callback> copy(Scheduler::FrameOnceSignal);
Scheduler::FrameOnceSignal.clear();
copy();
}
void Scheduler::OnDelay(Utils::Slot<Scheduler::Callback> callback, std::chrono::nanoseconds delay)
{
Scheduler::DelayedSlot slot;
slot.callback = callback;
slot.delay = delay;
Scheduler::DelayedSlots.push_back(slot);
}
void Scheduler::DelaySignal()
{
Utils::Signal<Scheduler::Callback> 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();
}
}

View File

@ -0,0 +1,41 @@
#pragma once
namespace Components
{
class Scheduler : public Component
{
public:
typedef void(Callback)();
Scheduler();
~Scheduler();
static void OnShutdown(Utils::Slot<Callback> callback);
static void OnFrame(Utils::Slot<Callback> callback);
static void OnReady(Utils::Slot<Callback> callback);
static void Once(Utils::Slot<Callback> callback);
static void OnDelay(Utils::Slot<Callback> callback, std::chrono::nanoseconds delay);
static void FrameHandler();
private:
class DelayedSlot
{
public:
std::chrono::nanoseconds delay;
Utils::Time::Interval interval;
Utils::Slot<Callback> callback;
};
static Utils::Signal<Callback> FrameSignal;
static Utils::Signal<Callback> FrameOnceSignal;
static std::vector<DelayedSlot> DelayedSlots;
static bool ReadyPassed;
static Utils::Signal<Callback> ReadySignal;
static Utils::Signal<Callback> ShutdownSignal;
static void ReadyHandler();
static void DelaySignal();
};
}

View File

@ -8,7 +8,7 @@ namespace Components
std::vector<std::string> Script::ScriptNameStack; std::vector<std::string> Script::ScriptNameStack;
unsigned short Script::FunctionName; unsigned short Script::FunctionName;
Utils::Signal<Script::Callback> Script::VMShutdownSignal; Utils::Signal<Scheduler::Callback> Script::VMShutdownSignal;
void Script::FunctionError() void Script::FunctionError()
{ {
@ -247,7 +247,7 @@ namespace Components
Script::ScriptFunctions.push_back({ name, function, isDev }); Script::ScriptFunctions.push_back({ name, function, isDev });
} }
void Script::OnVMShutdown(Utils::Slot<Script::Callback> callback) void Script::OnVMShutdown(Utils::Slot<Scheduler::Callback> callback)
{ {
Script::VMShutdownSignal.connect(callback); Script::VMShutdownSignal.connect(callback);
} }

View File

@ -6,8 +6,6 @@ namespace Components
class Script : public Component class Script : public Component
{ {
public: public:
typedef void(Callback)();
class Function class Function
{ {
public: public:
@ -29,7 +27,7 @@ namespace Components
static int LoadScriptAndLabel(std::string script, std::string label); 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 AddFunction(std::string name, Game::scr_function_t function, bool isDev = false);
static void OnVMShutdown(Utils::Slot<Callback> callback); static void OnVMShutdown(Utils::Slot<Scheduler::Callback> callback);
private: private:
static std::string ScriptName; static std::string ScriptName;
@ -38,7 +36,7 @@ namespace Components
static std::vector<std::string> ScriptNameStack; static std::vector<std::string> ScriptNameStack;
static unsigned short FunctionName; static unsigned short FunctionName;
static Utils::Signal<Callback> VMShutdownSignal; static Utils::Signal<Scheduler::Callback> VMShutdownSignal;
static void CompileError(unsigned int offset, const char* message, ...); static void CompileError(unsigned int offset, const char* message, ...);
static void PrintSourcePos(const char* filename, unsigned int offset); static void PrintSourcePos(const char* filename, unsigned int offset);

View File

@ -849,11 +849,11 @@ namespace Components
UIScript::AddOwnerDraw(253, ServerList::UpdateGameType); UIScript::AddOwnerDraw(253, ServerList::UpdateGameType);
// Add frame callback // Add frame callback
Renderer::OnFrame(ServerList::Frame); Scheduler::OnFrame(ServerList::Frame);
// This is placed here in case the anticheat has been disabled! // This is placed here in case the anticheat has been disabled!
#if !defined(DEBUG) && !defined(DISABLE_ANTICHEAT) && defined(PROCTECT_PROCESS) #if !defined(DEBUG) && !defined(DISABLE_ANTICHEAT) && defined(PROCTECT_PROCESS)
Renderer::OnFrame(AntiCheat::ReadIntegrityCheck); Scheduler::OnFrame(AntiCheat::ReadIntegrityCheck);
#endif #endif
} }

View File

@ -159,7 +159,7 @@ namespace Components
QuickPatch::OnReady([]() QuickPatch::OnReady([]()
{ {
Renderer::OnFrame(Toast::Handler); Scheduler::OnFrame(Toast::Handler);
}); });
Command::Add("testtoast", [] (Command::Params*) Command::Add("testtoast", [] (Command::Params*)

View File

@ -140,7 +140,7 @@ namespace Components
Utils::Hook(0x48E5D3, Window::DrawCursorStub, HOOK_CALL).install()->quick(); Utils::Hook(0x48E5D3, Window::DrawCursorStub, HOOK_CALL).install()->quick();
// Draw the cursor if necessary // Draw the cursor if necessary
Renderer::OnFrame([] () Scheduler::OnFrame([] ()
{ {
if (Window::NativeCursor.get<bool>() && IsWindow(Window::MainWindow) && GetForegroundWindow() == Window::MainWindow && Window::IsCursorWithin(Window::MainWindow)) if (Window::NativeCursor.get<bool>() && IsWindow(Window::MainWindow) && GetForegroundWindow() == Window::MainWindow && Window::IsCursorWithin(Window::MainWindow))
{ {