mirror of
https://github.com/XLabsProject/s1x-client.git
synced 2023-08-02 15:02:12 +02:00
motd: fix crash, cleanup code
This commit is contained in:
parent
2aea5f776f
commit
cb8f092c83
@ -15,7 +15,7 @@ namespace motd
|
||||
{
|
||||
std::string motd_resource = utils::nt::load_resource(DW_MOTD);
|
||||
std::future<std::optional<std::string>> motd_future;
|
||||
std::string marketing_featured_msg;
|
||||
std::string marketing_featured;
|
||||
}
|
||||
|
||||
std::string get_text()
|
||||
@ -33,11 +33,11 @@ namespace motd
|
||||
|
||||
utils::hook::detour marketing_get_message_hook;
|
||||
|
||||
bool marketing_get_message_stub(int controller, int location, char* message, int max_length)
|
||||
bool marketing_get_message_stub(int /*controller_index*/, int /*location-id*/, char* message_text, int message_text_length)
|
||||
{
|
||||
if (marketing_featured_msg.empty()) return false;
|
||||
if (marketing_featured.empty()) return false;
|
||||
|
||||
strncpy_s(message, marketing_featured_msg.length() + 1, marketing_featured_msg.data(), max_length);
|
||||
strncpy_s(message_text, message_text_length, marketing_featured.data(), _TRUNCATE);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -48,18 +48,18 @@ namespace motd
|
||||
void post_load() override
|
||||
{
|
||||
motd_future = utils::http::get_data_async("https://xlabs.dev/s1/motd.txt");
|
||||
std::thread([]()
|
||||
std::thread([]
|
||||
{
|
||||
auto data = utils::http::get_data("https://xlabs.dev/s1/motd.png");
|
||||
if (data)
|
||||
if (data.has_value())
|
||||
{
|
||||
images::override_texture("iotd_image", data.value());
|
||||
}
|
||||
|
||||
auto featured_optional = utils::http::get_data("https://xlabs.dev/s1/featured_msg.json");
|
||||
if (featured_optional)
|
||||
if (featured_optional.has_value())
|
||||
{
|
||||
marketing_featured_msg = featured_optional.value();
|
||||
marketing_featured = featured_optional.value();
|
||||
}
|
||||
|
||||
}).detach();
|
||||
@ -67,7 +67,18 @@ namespace motd
|
||||
|
||||
void post_unpack() override
|
||||
{
|
||||
marketing_get_message_hook.create(0x140126930, marketing_get_message_stub); // not sure why but in s1x, client doesnt ask for maketing messages from demonware even though marketing_active set to true
|
||||
if (!game::environment::is_mp())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Not sure why but in S1x, client doesn't ask for maketing messages from demonware even though marketing_active set to true
|
||||
marketing_get_message_hook.create(0x140126930, marketing_get_message_stub);
|
||||
}
|
||||
|
||||
void pre_destroy() override
|
||||
{
|
||||
marketing_get_message_hook.clear();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user