diff --git a/src/client/component/motd.cpp b/src/client/component/motd.cpp index fc02cb3..63046d0 100644 --- a/src/client/component/motd.cpp +++ b/src/client/component/motd.cpp @@ -15,7 +15,7 @@ namespace motd { std::string motd_resource = utils::nt::load_resource(DW_MOTD); std::future> 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,26 +48,37 @@ 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.has_value()) { - auto data = utils::http::get_data("https://xlabs.dev/s1/motd.png"); - if (data) - { - images::override_texture("iotd_image", data.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) - { - marketing_featured_msg = featured_optional.value(); - } + auto featured_optional = utils::http::get_data("https://xlabs.dev/s1/featured_msg.json"); + if (featured_optional.has_value()) + { + marketing_featured = featured_optional.value(); + } - }).detach(); + }).detach(); } 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(); } }; }