2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2023-01-03 07:16:44 -05:00
|
|
|
#include <Utils/InfoString.hpp>
|
2015-12-23 08:45:53 -05:00
|
|
|
|
2022-12-26 07:07:24 -05:00
|
|
|
#include "Modules/Bans.hpp"
|
|
|
|
#include "Modules/Bots.hpp"
|
|
|
|
#include "Modules/Branding.hpp"
|
|
|
|
#include "Modules/Bullet.hpp"
|
|
|
|
#include "Modules/CardTitles.hpp"
|
|
|
|
#include "Modules/Ceg.hpp"
|
|
|
|
#include "Modules/Changelog.hpp"
|
|
|
|
#include "Modules/Chat.hpp"
|
|
|
|
#include "Modules/ClanTags.hpp"
|
|
|
|
#include "Modules/ClientCommand.hpp"
|
|
|
|
#include "Modules/ConnectProtocol.hpp"
|
|
|
|
#include "Modules/Console.hpp"
|
|
|
|
#include "Modules/D3D9Ex.hpp"
|
|
|
|
#include "Modules/Debug.hpp"
|
2023-02-08 14:57:27 -05:00
|
|
|
#include "Modules/Discord.hpp"
|
2022-12-26 07:07:24 -05:00
|
|
|
#include "Modules/Discovery.hpp"
|
|
|
|
#include "Modules/Download.hpp"
|
|
|
|
#include "Modules/Elevators.hpp"
|
2023-01-03 07:16:44 -05:00
|
|
|
#include "Modules/FastFiles.hpp"
|
2022-12-26 07:07:24 -05:00
|
|
|
#include "Modules/Gamepad.hpp"
|
|
|
|
#include "Modules/Lean.hpp"
|
|
|
|
#include "Modules/MapDump.hpp"
|
|
|
|
#include "Modules/MapRotation.hpp"
|
|
|
|
#include "Modules/NetworkDebug.hpp"
|
|
|
|
#include "Modules/News.hpp"
|
2023-01-03 07:16:44 -05:00
|
|
|
#include "Modules/Party.hpp"
|
2022-12-26 07:07:24 -05:00
|
|
|
#include "Modules/PlayerMovement.hpp"
|
|
|
|
#include "Modules/PlayerName.hpp"
|
|
|
|
#include "Modules/Playlist.hpp"
|
|
|
|
#include "Modules/QuickPatch.hpp"
|
|
|
|
#include "Modules/RawFiles.hpp"
|
|
|
|
#include "Modules/RawMouse.hpp"
|
|
|
|
#include "Modules/RCon.hpp"
|
|
|
|
#include "Modules/Security.hpp"
|
|
|
|
#include "Modules/ServerCommands.hpp"
|
|
|
|
#include "Modules/ServerInfo.hpp"
|
|
|
|
#include "Modules/ServerList.hpp"
|
|
|
|
#include "Modules/Session.hpp"
|
|
|
|
#include "Modules/SlowMotion.hpp"
|
|
|
|
#include "Modules/SoundMutexFix.hpp"
|
|
|
|
#include "Modules/StartupMessages.hpp"
|
|
|
|
#include "Modules/Stats.hpp"
|
|
|
|
#include "Modules/StringTable.hpp"
|
|
|
|
#include "Modules/StructuredData.hpp"
|
|
|
|
#include "Modules/Theatre.hpp"
|
|
|
|
#include "Modules/Threading.hpp"
|
|
|
|
#include "Modules/UIFeeder.hpp"
|
|
|
|
#include "Modules/UserInfo.hpp"
|
|
|
|
#include "Modules/VisionFile.hpp"
|
|
|
|
#include "Modules/Voice.hpp"
|
|
|
|
#include "Modules/Vote.hpp"
|
|
|
|
#include "Modules/Weapon.hpp"
|
|
|
|
|
2023-02-01 05:10:24 -05:00
|
|
|
#include "Modules/BotLib/lPrecomp.hpp"
|
|
|
|
|
2015-12-23 08:45:53 -05:00
|
|
|
namespace Components
|
|
|
|
{
|
2016-09-03 09:52:40 -04:00
|
|
|
bool Loader::Pregame = true;
|
2017-01-23 16:06:50 -05:00
|
|
|
bool Loader::Postgame = false;
|
2017-06-04 07:46:50 -04:00
|
|
|
bool Loader::Uninitializing = false;
|
2015-12-23 08:45:53 -05:00
|
|
|
std::vector<Component*> Loader::Components;
|
|
|
|
|
2016-09-03 09:52:40 -04:00
|
|
|
bool Loader::IsPregame()
|
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
return Pregame;
|
2016-09-03 09:52:40 -04:00
|
|
|
}
|
|
|
|
|
2017-02-24 07:30:31 -05:00
|
|
|
bool Loader::IsPostgame()
|
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
return Postgame;
|
2017-02-24 07:30:31 -05:00
|
|
|
}
|
|
|
|
|
2017-06-04 07:46:50 -04:00
|
|
|
bool Loader::IsUninitializing()
|
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
return Uninitializing;
|
2017-06-04 07:46:50 -04:00
|
|
|
}
|
|
|
|
|
2015-12-23 08:45:53 -05:00
|
|
|
void Loader::Initialize()
|
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
Pregame = true;
|
|
|
|
Postgame = false;
|
|
|
|
Uninitializing = false;
|
2017-06-02 09:36:20 -04:00
|
|
|
Utils::Memory::GetAllocator()->clear();
|
2016-09-03 09:52:40 -04:00
|
|
|
|
2023-01-06 17:06:10 -05:00
|
|
|
// High priority
|
|
|
|
Register(new Singleton());
|
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
Register(new Auth());
|
|
|
|
Register(new Command());
|
|
|
|
Register(new Dvar());
|
2023-01-06 17:06:10 -05:00
|
|
|
Register(new Exception()); // Install our exception handler as early as possible to get better debug dumps from startup crashes
|
|
|
|
Register(new IPCPipe());
|
2022-12-25 12:23:53 -05:00
|
|
|
Register(new Network());
|
|
|
|
Register(new Logger());
|
|
|
|
Register(new UIScript());
|
|
|
|
Register(new ZoneBuilder());
|
|
|
|
|
|
|
|
Register(new ArenaLength());
|
|
|
|
Register(new AssetHandler());
|
|
|
|
Register(new Bans());
|
|
|
|
Register(new Bots());
|
|
|
|
Register(new Branding());
|
|
|
|
Register(new Bullet());
|
|
|
|
Register(new CardTitles());
|
|
|
|
Register(new Ceg());
|
|
|
|
Register(new Changelog());
|
|
|
|
Register(new Chat());
|
|
|
|
Register(new ClanTags());
|
|
|
|
Register(new ClientCommand());
|
|
|
|
Register(new ConnectProtocol());
|
|
|
|
Register(new Console());
|
|
|
|
Register(new D3D9Ex());
|
|
|
|
Register(new Debug());
|
|
|
|
Register(new Dedicated());
|
2023-02-08 14:57:27 -05:00
|
|
|
Register(new Discord());
|
2022-12-25 12:23:53 -05:00
|
|
|
Register(new Discovery());
|
|
|
|
Register(new Download());
|
|
|
|
Register(new Elevators());
|
|
|
|
Register(new Events());
|
|
|
|
Register(new FastFiles());
|
|
|
|
Register(new FileSystem());
|
|
|
|
Register(new Friends());
|
|
|
|
Register(new Gamepad());
|
|
|
|
Register(new Lean());
|
|
|
|
Register(new Localization());
|
|
|
|
Register(new MapDump());
|
|
|
|
Register(new MapRotation());
|
|
|
|
Register(new Maps());
|
|
|
|
Register(new Materials());
|
|
|
|
Register(new Menus());
|
|
|
|
Register(new ModList());
|
|
|
|
Register(new ModelSurfs());
|
|
|
|
Register(new NetworkDebug());
|
|
|
|
Register(new News());
|
|
|
|
Register(new Node());
|
|
|
|
Register(new Party());
|
|
|
|
Register(new PlayerMovement());
|
|
|
|
Register(new PlayerName());
|
|
|
|
Register(new Playlist());
|
|
|
|
Register(new QuickPatch());
|
|
|
|
Register(new RawFiles());
|
|
|
|
Register(new RawMouse());
|
2022-12-26 07:07:24 -05:00
|
|
|
Register(new RCon());
|
2022-12-25 12:23:53 -05:00
|
|
|
Register(new Renderer());
|
|
|
|
Register(new Scheduler());
|
|
|
|
Register(new Security());
|
|
|
|
Register(new ServerCommands());
|
|
|
|
Register(new ServerInfo());
|
|
|
|
Register(new ServerList());
|
|
|
|
Register(new Session());
|
|
|
|
Register(new SlowMotion());
|
|
|
|
Register(new SoundMutexFix());
|
|
|
|
Register(new StartupMessages());
|
|
|
|
Register(new Stats());
|
|
|
|
Register(new StringTable());
|
|
|
|
Register(new StructuredData());
|
|
|
|
Register(new TextRenderer());
|
|
|
|
Register(new Theatre());
|
|
|
|
Register(new Threading());
|
|
|
|
Register(new Toast());
|
|
|
|
Register(new UIFeeder());
|
|
|
|
Register(new UserInfo());
|
|
|
|
Register(new VisionFile());
|
|
|
|
Register(new Voice());
|
|
|
|
Register(new Vote());
|
|
|
|
Register(new Weapon());
|
|
|
|
Register(new Window());
|
|
|
|
Register(new Zones());
|
|
|
|
|
|
|
|
Register(new GSC());
|
|
|
|
|
2023-02-01 05:10:24 -05:00
|
|
|
Register(new lPrecomp());
|
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
Pregame = false;
|
2022-06-16 10:15:26 -04:00
|
|
|
|
|
|
|
// Make sure preDestroy is called when the game shuts down
|
2022-12-25 12:23:53 -05:00
|
|
|
Scheduler::OnGameShutdown(PreDestroy);
|
2015-12-23 08:45:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void Loader::Uninitialize()
|
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
Uninitializing = true;
|
|
|
|
PreDestroyNoPostGame();
|
2017-01-23 16:06:50 -05:00
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
std::reverse(Components.begin(), Components.end());
|
|
|
|
for (auto& component : Components)
|
2015-12-23 08:45:53 -05:00
|
|
|
{
|
2016-08-14 10:18:44 -04:00
|
|
|
#ifdef DEBUG
|
2022-12-25 12:23:53 -05:00
|
|
|
if (!IsPerformingUnitTests())
|
2016-09-16 05:04:28 -04:00
|
|
|
{
|
2022-06-12 17:07:53 -04:00
|
|
|
Logger::Print("Unregister component: {}\n", component->getName());
|
2016-09-16 05:04:28 -04:00
|
|
|
}
|
2016-08-14 10:18:44 -04:00
|
|
|
#endif
|
2015-12-23 08:45:53 -05:00
|
|
|
delete component;
|
|
|
|
}
|
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
Components.clear();
|
2017-06-02 09:36:20 -04:00
|
|
|
Utils::Memory::GetAllocator()->clear();
|
2022-12-25 12:23:53 -05:00
|
|
|
Uninitializing = false;
|
2015-12-23 08:45:53 -05:00
|
|
|
}
|
|
|
|
|
2017-01-23 16:06:50 -05:00
|
|
|
void Loader::PreDestroy()
|
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
if (!Postgame)
|
2017-01-23 16:06:50 -05:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
Postgame = true;
|
2017-01-23 16:06:50 -05:00
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
auto components = Components;
|
2017-02-24 07:30:31 -05:00
|
|
|
|
|
|
|
std::reverse(components.begin(), components.end());
|
2022-12-25 12:23:53 -05:00
|
|
|
for (auto& component : components)
|
2017-01-23 16:06:50 -05:00
|
|
|
{
|
|
|
|
component->preDestroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-24 07:30:31 -05:00
|
|
|
void Loader::PreDestroyNoPostGame()
|
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
if (!Postgame)
|
2017-02-24 07:30:31 -05:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
auto components = Components;
|
2017-02-24 07:30:31 -05:00
|
|
|
|
|
|
|
std::reverse(components.begin(), components.end());
|
2022-12-25 12:23:53 -05:00
|
|
|
for (auto& component : components)
|
2017-02-24 07:30:31 -05:00
|
|
|
{
|
|
|
|
component->preDestroy();
|
|
|
|
}
|
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
Postgame = true;
|
2017-02-24 07:30:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-04 15:58:49 -05:00
|
|
|
bool Loader::PerformUnitTests()
|
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
|
|
|
|
Logger::Print("Performing unit tests for components:\n");
|
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
for (const auto& component : Components)
|
2016-02-04 15:58:49 -05:00
|
|
|
{
|
2022-06-13 11:32:45 -04:00
|
|
|
#if defined(FORCE_UNIT_TESTS)
|
|
|
|
Logger::Debug("Testing '{}'...\n", component->getName());
|
2016-08-15 11:07:32 -04:00
|
|
|
#endif
|
2016-02-04 15:58:49 -05:00
|
|
|
auto startTime = std::chrono::high_resolution_clock::now();
|
2022-06-13 11:32:45 -04:00
|
|
|
auto testRes = component->unitTest();
|
2016-02-04 15:58:49 -05:00
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime).count();
|
2022-06-12 17:07:53 -04:00
|
|
|
Logger::Print("Test done ({}ms): {}\n\n", duration, (testRes ? "Success" : "Error"));
|
2016-02-04 15:58:49 -05:00
|
|
|
result &= testRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-07-12 05:37:23 -04:00
|
|
|
bool Loader::IsPerformingUnitTests()
|
2016-02-04 15:58:49 -05:00
|
|
|
{
|
2016-02-19 17:57:06 -05:00
|
|
|
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
|
2016-02-04 15:58:49 -05:00
|
|
|
return Flags::HasFlag("tests");
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-12-23 08:45:53 -05:00
|
|
|
void Loader::Register(Component* component)
|
|
|
|
{
|
|
|
|
if (component)
|
|
|
|
{
|
2017-06-12 13:54:11 -04:00
|
|
|
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
|
2022-12-25 12:23:53 -05:00
|
|
|
if (!IsPerformingUnitTests())
|
2016-09-16 05:04:28 -04:00
|
|
|
{
|
2022-06-12 17:07:53 -04:00
|
|
|
Logger::Print("Component registered: {}\n", component->getName());
|
2016-09-16 05:04:28 -04:00
|
|
|
}
|
2016-08-14 10:18:44 -04:00
|
|
|
#endif
|
2022-12-25 12:23:53 -05:00
|
|
|
Components.push_back(component);
|
2015-12-23 08:45:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|