2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-11-26 12:38:34 -05:00
|
|
|
#include <version.hpp>
|
|
|
|
|
2017-02-04 14:45:27 -05:00
|
|
|
#define NEWS_MOTD_DEFAULT "Welcome to IW4x Multiplayer!"
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
bool News::Terminate;
|
|
|
|
std::thread News::Thread;
|
|
|
|
|
|
|
|
bool News::unitTest()
|
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
|
2022-12-18 16:47:59 -05:00
|
|
|
if (Thread.joinable())
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Awaiting thread termination...");
|
2022-12-18 16:47:59 -05:00
|
|
|
Thread.join();
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-12-18 16:47:59 -05:00
|
|
|
if (!std::strcmp(Localization::Get("MPUI_MOTD_TEXT"), NEWS_MOTD_DEFAULT))
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
Logger::Print("Failed to fetch motd!\n");
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Successfully fetched motd");
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* News::GetNewsText()
|
|
|
|
{
|
|
|
|
return Localization::Get("MPUI_MOTD_TEXT");
|
|
|
|
}
|
|
|
|
|
|
|
|
News::News()
|
|
|
|
{
|
2017-02-21 15:47:02 -05:00
|
|
|
if (ZoneBuilder::IsEnabled() || Dedicated::IsEnabled()) return; // Maybe also dedi?
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-03-08 07:20:28 -05:00
|
|
|
Dvar::Register<bool>("g_firstLaunch", true, Game::DVAR_ARCHIVE, "");
|
2017-01-29 15:43:57 -05:00
|
|
|
|
2022-08-24 10:38:14 -04:00
|
|
|
UIScript::Add("checkFirstLaunch", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
2017-01-29 15:43:57 -05:00
|
|
|
{
|
|
|
|
if (Dvar::Var("g_firstLaunch").get<bool>())
|
|
|
|
{
|
|
|
|
Command::Execute("openmenu menu_first_launch", false);
|
2022-12-18 16:47:59 -05:00
|
|
|
//Dvar::Var("g_firstLaunch").set(false); // The menus should set it
|
2017-01-29 15:43:57 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-24 10:38:14 -04:00
|
|
|
UIScript::Add("visitWebsite", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
2017-01-29 15:42:35 -05:00
|
|
|
{
|
2022-12-06 08:05:03 -05:00
|
|
|
Utils::OpenUrl(Utils::Cache::GetUrl(Utils::Cache::Urls[1], {}));
|
2017-01-29 15:42:35 -05:00
|
|
|
});
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
Localization::Set("MPUI_CHANGELOG_TEXT", "Loading...");
|
2017-02-04 14:45:27 -05:00
|
|
|
Localization::Set("MPUI_MOTD_TEXT", NEWS_MOTD_DEFAULT);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
// make newsfeed (ticker) menu items not cut off based on safe area
|
|
|
|
Utils::Hook::Nop(0x63892D, 5);
|
|
|
|
|
|
|
|
// hook for getting the news ticker string
|
|
|
|
Utils::Hook::Nop(0x6388BB, 2); // skip the "if (item->text[0] == '@')" localize check
|
2022-12-18 16:47:59 -05:00
|
|
|
Utils::Hook(0x6388C1, GetNewsText, HOOK_CALL).install()->quick();
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2017-07-03 09:40:32 -04:00
|
|
|
if (!Utils::IsWineEnvironment() && !Loader::IsPerformingUnitTests())
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2022-12-18 16:47:59 -05:00
|
|
|
Terminate = false;
|
|
|
|
Thread = std::thread([]()
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2017-02-04 15:52:49 -05:00
|
|
|
Changelog::LoadChangelog();
|
2022-12-18 16:47:59 -05:00
|
|
|
if (Terminate) return;
|
2017-02-04 14:26:46 -05:00
|
|
|
|
2017-01-25 08:34:53 -05:00
|
|
|
std::string data = Utils::Cache::GetFile("/iw4/motd.txt");
|
|
|
|
if (!data.empty())
|
|
|
|
{
|
|
|
|
Localization::Set("MPUI_MOTD_TEXT", data);
|
|
|
|
}
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-12-18 16:47:59 -05:00
|
|
|
if (!Loader::IsPerformingUnitTests() && !Terminate)
|
2017-01-25 08:34:53 -05:00
|
|
|
{
|
2022-12-18 16:47:59 -05:00
|
|
|
while (!Terminate)
|
2017-01-22 14:12:36 -05:00
|
|
|
{
|
2017-01-25 08:34:53 -05:00
|
|
|
// Sleep for 3 minutes
|
2022-12-18 16:47:59 -05:00
|
|
|
for (int i = 0; i < 180 && !Terminate; ++i)
|
2017-01-25 08:34:53 -05:00
|
|
|
{
|
|
|
|
std::this_thread::sleep_for(1s);
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-23 16:06:50 -05:00
|
|
|
void News::preDestroy()
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2022-12-18 16:47:59 -05:00
|
|
|
Terminate = true;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-12-18 16:47:59 -05:00
|
|
|
if (Thread.joinable())
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2022-12-18 16:47:59 -05:00
|
|
|
Thread.join();
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|