2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2017-01-19 16:23:59 -05:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (News::Thread.joinable())
|
|
|
|
{
|
|
|
|
Logger::Print("Awaiting thread termination...\n");
|
|
|
|
News::Thread.join();
|
|
|
|
|
2017-02-04 14:45:27 -05:00
|
|
|
if (!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
|
|
|
|
{
|
|
|
|
Logger::Print("Successfully fetched motd.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04-07 05:41:20 -04:00
|
|
|
Dvar::Register<bool>("g_firstLaunch", true, Game::DVAR_ARCHIVE, "");
|
2017-01-29 15:43:57 -05:00
|
|
|
|
2022-04-07 05:41:20 -04:00
|
|
|
Dvar::Register<int>("cl_updateoldversion", REVISION, REVISION, REVISION, Game::DVAR_WRITEPROTECTED, "Current version number.");
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2017-01-29 15:43:57 -05:00
|
|
|
UIScript::Add("checkFirstLaunch", [](UIScript::Token)
|
|
|
|
{
|
|
|
|
if (Dvar::Var("g_firstLaunch").get<bool>())
|
|
|
|
{
|
|
|
|
Command::Execute("openmenu menu_first_launch", false);
|
|
|
|
//Dvar::Var("g_firstLaunch").set(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-01-29 15:42:35 -05:00
|
|
|
UIScript::Add("visitWebsite", [](UIScript::Token)
|
|
|
|
{
|
2017-06-11 15:25:00 -04:00
|
|
|
Utils::OpenUrl(Utils::Cache::GetStaticUrl(""));
|
2017-01-29 15:42:35 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
UIScript::Add("visitWiki", [](UIScript::Token)
|
|
|
|
{
|
2019-12-26 07:46:40 -05:00
|
|
|
//Utils::OpenUrl(Utils::Cache::GetStaticUrl("/wiki/"));
|
2021-06-25 18:28:01 -04:00
|
|
|
Utils::OpenUrl("https://github.com/Emosewaj/IW4x/wiki");
|
2017-01-29 15:42:35 -05:00
|
|
|
});
|
2017-01-29 15:43:57 -05:00
|
|
|
|
2019-01-07 12:09:48 -05:00
|
|
|
UIScript::Add("visitDiscord", [](UIScript::Token)
|
|
|
|
{
|
2019-01-10 04:24:22 -05:00
|
|
|
Utils::OpenUrl("https://discord.gg/sKeVmR3");
|
2019-01-07 12:09:48 -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
|
|
|
|
Utils::Hook(0x6388C1, News::GetNewsText, HOOK_CALL).install()->quick();
|
|
|
|
|
2017-07-03 09:40:32 -04:00
|
|
|
if (!Utils::IsWineEnvironment() && !Loader::IsPerformingUnitTests())
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
News::Terminate = false;
|
2017-01-25 08:34:53 -05:00
|
|
|
News::Thread = std::thread([]()
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2017-02-04 15:52:49 -05:00
|
|
|
Changelog::LoadChangelog();
|
2017-06-04 14:51:18 -04:00
|
|
|
if (News::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
|
|
|
|
2017-07-03 09:40:32 -04:00
|
|
|
if (!Loader::IsPerformingUnitTests() && !News::Terminate)
|
2017-01-25 08:34:53 -05:00
|
|
|
{
|
|
|
|
while (!News::Terminate)
|
2017-01-22 14:12:36 -05:00
|
|
|
{
|
2017-01-25 08:34:53 -05:00
|
|
|
// Sleep for 3 minutes
|
|
|
|
for (int i = 0; i < 180 && !News::Terminate; ++i)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
News::Terminate = true;
|
|
|
|
|
|
|
|
if (News::Thread.joinable())
|
|
|
|
{
|
|
|
|
News::Thread.join();
|
|
|
|
}
|
2017-01-22 14:12:36 -05:00
|
|
|
|
|
|
|
News::Thread = std::thread();
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
}
|