2019-07-31 22:21:02 +02:00
|
|
|
#ifndef __INCLUDED_STEAM_OVERLAY_H__
|
|
|
|
#define __INCLUDED_STEAM_OVERLAY_H__
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2023-12-27 09:15:10 +02:00
|
|
|
#include "dll/base.h"
|
2019-08-02 11:16:30 +02:00
|
|
|
#include <map>
|
2019-08-02 13:02:20 +02:00
|
|
|
#include <queue>
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2024-03-12 21:21:09 +02:00
|
|
|
#ifdef EMU_OVERLAY
|
|
|
|
|
|
|
|
#include <future>
|
|
|
|
#include <atomic>
|
|
|
|
#include <memory>
|
|
|
|
#include "InGameOverlay/RendererHook.h"
|
|
|
|
|
2019-08-03 12:58:48 +02:00
|
|
|
static constexpr size_t max_chat_len = 768;
|
|
|
|
|
2019-08-02 13:02:20 +02:00
|
|
|
enum window_state
|
2019-07-31 22:21:02 +02:00
|
|
|
{
|
2019-08-16 18:31:56 +02:00
|
|
|
window_state_none = 0,
|
|
|
|
window_state_show = 1<<0,
|
|
|
|
window_state_invite = 1<<1,
|
|
|
|
window_state_join = 1<<2,
|
|
|
|
window_state_lobby_invite = 1<<3,
|
|
|
|
window_state_rich_invite = 1<<4,
|
|
|
|
window_state_send_message = 1<<5,
|
|
|
|
window_state_need_attention = 1<<6,
|
2019-07-31 22:21:02 +02:00
|
|
|
};
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2019-08-02 13:02:20 +02:00
|
|
|
struct friend_window_state
|
2019-08-02 11:16:30 +02:00
|
|
|
{
|
2019-10-11 13:10:48 +02:00
|
|
|
int id;
|
2019-08-02 13:02:20 +02:00
|
|
|
uint8 window_state;
|
2019-10-14 16:35:36 +02:00
|
|
|
std::string window_title;
|
2019-08-03 12:58:48 +02:00
|
|
|
union // The invitation (if any)
|
2019-08-02 11:16:30 +02:00
|
|
|
{
|
|
|
|
uint64 lobbyId;
|
|
|
|
char connect[k_cchMaxRichPresenceValueLength];
|
|
|
|
};
|
2019-08-03 12:58:48 +02:00
|
|
|
std::string chat_history;
|
|
|
|
char chat_input[max_chat_len];
|
2020-01-26 09:46:57 -05:00
|
|
|
|
2020-02-02 19:07:30 -05:00
|
|
|
bool joinable;
|
2019-08-02 11:16:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Friend_Less
|
|
|
|
{
|
|
|
|
bool operator()(const Friend& lhs, const Friend& rhs) const
|
|
|
|
{
|
|
|
|
return lhs.id() < rhs.id();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-08 15:52:38 +01:00
|
|
|
enum notification_type
|
|
|
|
{
|
|
|
|
notification_type_message = 0,
|
|
|
|
notification_type_invite,
|
|
|
|
notification_type_achievement,
|
2024-01-06 07:41:32 +02:00
|
|
|
notification_type_auto_accept_invite,
|
2019-11-08 15:52:38 +01:00
|
|
|
};
|
|
|
|
|
2019-09-04 19:31:31 +02:00
|
|
|
struct Notification
|
|
|
|
{
|
2024-01-26 05:49:03 +02:00
|
|
|
static constexpr float width_percent = 0.25f; // percentage from total width
|
2024-03-06 00:59:44 +02:00
|
|
|
static constexpr float height = 6.5f;
|
2019-09-04 19:31:31 +02:00
|
|
|
static constexpr std::chrono::milliseconds fade_in = std::chrono::milliseconds(2000);
|
|
|
|
static constexpr std::chrono::milliseconds fade_out = std::chrono::milliseconds(2000);
|
|
|
|
static constexpr std::chrono::milliseconds show_time = std::chrono::milliseconds(6000) + fade_in + fade_out;
|
|
|
|
static constexpr std::chrono::milliseconds fade_out_start = show_time - fade_out;
|
2019-10-11 13:10:48 +02:00
|
|
|
|
|
|
|
int id;
|
2019-11-08 15:52:38 +01:00
|
|
|
uint8 type;
|
2019-09-04 19:31:31 +02:00
|
|
|
std::chrono::seconds start_time;
|
|
|
|
std::string message;
|
2019-11-08 15:52:38 +01:00
|
|
|
std::pair<const Friend, friend_window_state>* frd;
|
2023-11-10 17:25:36 +02:00
|
|
|
std::weak_ptr<uint64_t> icon;
|
2019-09-04 19:31:31 +02:00
|
|
|
};
|
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
struct Overlay_Achievement
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::string title;
|
|
|
|
std::string description;
|
2023-11-10 17:25:36 +02:00
|
|
|
std::string icon_name;
|
2023-11-12 23:09:17 +02:00
|
|
|
std::string icon_gray_name;
|
2022-08-05 02:09:43 -04:00
|
|
|
bool hidden;
|
|
|
|
bool achieved;
|
|
|
|
uint32 unlock_time;
|
2023-11-10 17:25:36 +02:00
|
|
|
std::weak_ptr<uint64_t> icon;
|
2023-11-12 23:09:17 +02:00
|
|
|
std::weak_ptr<uint64_t> icon_gray;
|
2024-02-09 10:32:33 +02:00
|
|
|
|
2024-03-12 21:21:09 +02:00
|
|
|
// avoids spam loading on failure
|
2024-02-09 10:32:33 +02:00
|
|
|
constexpr const static int ICON_LOAD_MAX_TRIALS = 3;
|
|
|
|
uint8_t icon_load_trials = ICON_LOAD_MAX_TRIALS;
|
|
|
|
uint8_t icon_gray_load_trials = ICON_LOAD_MAX_TRIALS;
|
2022-08-05 02:09:43 -04:00
|
|
|
};
|
2019-08-14 14:55:31 +02:00
|
|
|
|
2024-03-07 02:57:48 +02:00
|
|
|
struct NotificationsIndexes
|
|
|
|
{
|
2024-01-26 05:49:03 +02:00
|
|
|
int top_left = 0, top_center = 0, top_right = 0;
|
|
|
|
int bot_left = 0, bot_center = 0, bot_right = 0;
|
|
|
|
};
|
|
|
|
|
2019-07-25 23:33:07 +02:00
|
|
|
class Steam_Overlay
|
|
|
|
{
|
2024-03-12 21:21:09 +02:00
|
|
|
constexpr static const char ACH_FALLBACK_DIR[] = "achievement_images";
|
|
|
|
|
2019-07-25 23:33:07 +02:00
|
|
|
Settings* settings;
|
|
|
|
SteamCallResults* callback_results;
|
|
|
|
SteamCallBacks* callbacks;
|
|
|
|
RunEveryRunCB* run_every_runcb;
|
2019-07-31 22:21:02 +02:00
|
|
|
Networking* network;
|
|
|
|
|
2019-08-02 11:16:30 +02:00
|
|
|
// friend id, show client window (to chat and accept invite maybe)
|
2024-03-14 19:23:39 +02:00
|
|
|
std::map<Friend, friend_window_state, Friend_Less> friends{};
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2024-03-04 02:39:50 +02:00
|
|
|
bool is_ready = false;
|
2024-03-14 19:23:39 +02:00
|
|
|
|
|
|
|
ENotificationPosition notif_position = ENotificationPosition::k_EPositionBottomLeft;
|
|
|
|
int h_inset = 0;
|
|
|
|
int v_inset = 0;
|
|
|
|
std::string show_url{};
|
|
|
|
|
|
|
|
std::vector<Overlay_Achievement> achievements{};
|
|
|
|
|
|
|
|
bool show_overlay = false;
|
|
|
|
bool show_achievements = false;
|
|
|
|
bool show_settings = false;
|
2022-08-05 02:09:43 -04:00
|
|
|
|
2023-12-29 03:55:11 +02:00
|
|
|
// disable input when force_*.txt file is used
|
2024-03-14 19:23:39 +02:00
|
|
|
bool disable_user_input = false;
|
2023-12-29 03:55:11 +02:00
|
|
|
// warn when force_*.txt file is used
|
2024-03-14 19:23:39 +02:00
|
|
|
bool warn_forced_setting = false;
|
2023-12-29 03:55:11 +02:00
|
|
|
// warn when using local save
|
2024-03-14 19:23:39 +02:00
|
|
|
bool warn_local_save = false;
|
2023-12-29 03:55:11 +02:00
|
|
|
// warn when app ID = 0
|
2024-03-14 19:23:39 +02:00
|
|
|
bool warn_bad_appid = false;
|
2022-08-05 02:09:43 -04:00
|
|
|
|
2024-03-14 19:23:39 +02:00
|
|
|
char username_text[256]{};
|
|
|
|
std::atomic<bool> save_settings = false;
|
2022-08-05 02:09:43 -04:00
|
|
|
|
2024-03-08 21:33:13 +02:00
|
|
|
int current_language = 0;
|
2022-08-05 02:09:43 -04:00
|
|
|
|
2024-03-08 21:33:13 +02:00
|
|
|
std::string warning_message{};
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
// Callback infos
|
2024-03-08 21:33:13 +02:00
|
|
|
std::queue<Friend> has_friend_action{};
|
|
|
|
std::vector<Notification> notifications{};
|
2024-01-22 01:31:02 +02:00
|
|
|
// used when the button "Invite all" is clicked
|
|
|
|
std::atomic<bool> invite_all_friends_clicked = false;
|
2020-01-26 17:24:16 -05:00
|
|
|
|
2024-03-14 19:23:39 +02:00
|
|
|
bool overlay_state_changed = false;
|
|
|
|
|
|
|
|
std::atomic<bool> i_have_lobby = false;
|
2019-07-31 22:21:02 +02:00
|
|
|
|
2024-03-14 19:23:39 +02:00
|
|
|
// some stuff has to be initialized once the renderer hook is ready
|
|
|
|
std::atomic<bool> late_init_imgui = false;
|
|
|
|
bool late_init_ach_icons = false;
|
2024-03-11 23:55:19 +02:00
|
|
|
|
|
|
|
// changed each time a notification is posted or overlay is shown/hidden
|
|
|
|
std::atomic_uint32_t renderer_frame_processing_requests = 0;
|
|
|
|
// changed only when overlay is shown/hidden, true means overlay is shown
|
2024-03-12 00:25:47 +02:00
|
|
|
std::atomic_uint32_t obscure_cursor_requests = 0;
|
2024-03-08 21:33:13 +02:00
|
|
|
|
|
|
|
constexpr static const int renderer_detector_polling_ms = 100;
|
|
|
|
std::future<InGameOverlay::RendererHook_t *> future_renderer{};
|
|
|
|
InGameOverlay::RendererHook_t *_renderer{};
|
2020-01-20 11:47:12 -05:00
|
|
|
|
2019-07-25 23:33:07 +02:00
|
|
|
Steam_Overlay(Steam_Overlay const&) = delete;
|
|
|
|
Steam_Overlay(Steam_Overlay&&) = delete;
|
|
|
|
Steam_Overlay& operator=(Steam_Overlay const&) = delete;
|
|
|
|
Steam_Overlay& operator=(Steam_Overlay&&) = delete;
|
|
|
|
|
2024-03-14 19:23:39 +02:00
|
|
|
static void overlay_run_callback(void* object);
|
|
|
|
static void overlay_networking_callback(void* object, Common_Message* msg);
|
|
|
|
|
2024-03-07 02:57:48 +02:00
|
|
|
bool is_friend_joinable(std::pair<const Friend, friend_window_state> &f);
|
|
|
|
bool got_lobby();
|
2019-08-06 13:46:43 +02:00
|
|
|
|
2024-03-04 02:39:50 +02:00
|
|
|
bool submit_notification(notification_type type, const std::string &msg, std::pair<const Friend, friend_window_state> *frd = nullptr, const std::weak_ptr<uint64_t> &icon = {});
|
|
|
|
|
2024-03-07 02:57:48 +02:00
|
|
|
void notify_sound_user_invite(friend_window_state& friend_state);
|
|
|
|
void notify_sound_user_achievement();
|
|
|
|
void notify_sound_auto_accept_friend_invite();
|
2019-09-04 19:31:31 +02:00
|
|
|
|
2019-08-02 15:26:16 +02:00
|
|
|
// Right click on friend
|
2024-03-07 02:57:48 +02:00
|
|
|
void build_friend_context_menu(Friend const& frd, friend_window_state &state);
|
2019-08-02 15:26:16 +02:00
|
|
|
// Double click on friend
|
2024-03-07 02:57:48 +02:00
|
|
|
void build_friend_window(Friend const& frd, friend_window_state &state);
|
2019-08-26 19:36:07 +02:00
|
|
|
// Notifications like achievements, chat and invitations
|
2024-03-07 02:57:48 +02:00
|
|
|
void set_next_notification_pos(float width, float height, float font_size, notification_type type, struct NotificationsIndexes &idx);
|
|
|
|
void build_notifications(int width, int height);
|
2024-01-22 01:31:02 +02:00
|
|
|
// invite a single friend
|
2024-03-07 02:57:48 +02:00
|
|
|
void invite_friend(uint64 friend_id, class Steam_Friends* steamFriends, class Steam_Matchmaking* steamMatchmaking);
|
2024-01-22 01:31:02 +02:00
|
|
|
|
2024-03-08 21:33:13 +02:00
|
|
|
void request_renderer_detector();
|
|
|
|
void renderer_detector_delay_thread();
|
2024-03-05 22:59:17 +02:00
|
|
|
void renderer_hook_init_thread();
|
|
|
|
|
2024-04-04 02:47:12 +02:00
|
|
|
// note: make sure to load all relevant strings before creating the font(s), otherwise some glyphs ranges will be missing
|
2024-03-07 02:57:48 +02:00
|
|
|
void create_fonts();
|
|
|
|
void load_audio();
|
2024-03-14 19:23:39 +02:00
|
|
|
void load_achievements_data();
|
|
|
|
void initial_load_achievements_icons();
|
2024-03-05 22:59:17 +02:00
|
|
|
|
2024-03-07 02:57:48 +02:00
|
|
|
void overlay_state_hook(bool ready);
|
2024-03-11 23:55:19 +02:00
|
|
|
void allow_renderer_frame_processing(bool state, bool cleaning_up_overlay = false);
|
2024-03-14 19:23:39 +02:00
|
|
|
void obscure_game_input(bool state);
|
2024-03-07 02:57:48 +02:00
|
|
|
|
|
|
|
void add_auto_accept_invite_notification();
|
|
|
|
|
2024-03-09 03:45:21 +02:00
|
|
|
void add_invite_notification(std::pair<const Friend, friend_window_state> &wnd_state);
|
2024-03-07 02:57:48 +02:00
|
|
|
|
|
|
|
void add_chat_message_notification(std::string const& message);
|
|
|
|
|
|
|
|
bool open_overlay_hook(bool toggle);
|
|
|
|
|
2024-03-12 21:21:09 +02:00
|
|
|
bool try_load_ach_icon(Overlay_Achievement &ach);
|
|
|
|
bool try_load_ach_gray_icon(Overlay_Achievement &ach);
|
|
|
|
|
2024-03-14 19:23:39 +02:00
|
|
|
void overlay_render_proc();
|
2024-03-19 22:07:43 +02:00
|
|
|
void render_main_window();
|
2024-03-14 19:23:39 +02:00
|
|
|
void networking_msg_received(Common_Message* msg);
|
|
|
|
void steam_run_callback();
|
|
|
|
|
2019-07-25 23:33:07 +02:00
|
|
|
public:
|
2019-07-31 22:21:02 +02:00
|
|
|
Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking *network);
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
~Steam_Overlay();
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
bool Ready() const;
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
bool NeedPresent() const;
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
void SetNotificationPosition(ENotificationPosition eNotificationPosition);
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
void SetNotificationInset(int nHorizontalInset, int nVerticalInset);
|
|
|
|
void SetupOverlay();
|
2022-08-07 23:11:21 -04:00
|
|
|
void UnSetupOverlay();
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
void OpenOverlayInvite(CSteamID lobbyId);
|
|
|
|
void OpenOverlay(const char* pchDialog);
|
2022-08-05 02:09:43 -04:00
|
|
|
void OpenOverlayWebpage(const char* pchURL);
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2019-08-18 16:22:07 +02:00
|
|
|
bool ShowOverlay() const;
|
2019-07-31 22:21:02 +02:00
|
|
|
void ShowOverlay(bool state);
|
2019-08-02 11:16:30 +02:00
|
|
|
|
2019-08-02 23:01:24 +02:00
|
|
|
void SetLobbyInvite(Friend friendId, uint64 lobbyId);
|
|
|
|
void SetRichInvite(Friend friendId, const char* connect_str);
|
2019-08-02 11:16:30 +02:00
|
|
|
|
|
|
|
void FriendConnect(Friend _friend);
|
|
|
|
void FriendDisconnect(Friend _friend);
|
2019-09-04 19:31:31 +02:00
|
|
|
|
2019-11-08 15:52:38 +01:00
|
|
|
void AddAchievementNotification(nlohmann::json const& ach);
|
2019-07-31 22:21:02 +02:00
|
|
|
};
|
2019-07-25 23:33:07 +02:00
|
|
|
|
2019-08-14 14:55:31 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
class Steam_Overlay
|
|
|
|
{
|
|
|
|
public:
|
2019-09-05 09:00:02 +02:00
|
|
|
Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking* network) {}
|
2019-08-14 18:11:00 +02:00
|
|
|
~Steam_Overlay() {}
|
2019-08-14 14:55:31 +02:00
|
|
|
|
2019-08-14 18:11:00 +02:00
|
|
|
bool Ready() const { return false; }
|
2019-08-14 14:55:31 +02:00
|
|
|
|
|
|
|
bool NeedPresent() const { return false; }
|
|
|
|
|
|
|
|
void SetNotificationPosition(ENotificationPosition eNotificationPosition) {}
|
|
|
|
|
|
|
|
void SetNotificationInset(int nHorizontalInset, int nVerticalInset) {}
|
|
|
|
void SetupOverlay() {}
|
2022-08-07 23:11:21 -04:00
|
|
|
void UnSetupOverlay() {}
|
2019-08-14 14:55:31 +02:00
|
|
|
|
|
|
|
void OpenOverlayInvite(CSteamID lobbyId) {}
|
|
|
|
void OpenOverlay(const char* pchDialog) {}
|
2022-08-05 02:09:43 -04:00
|
|
|
void OpenOverlayWebpage(const char* pchURL) {}
|
2019-08-14 14:55:31 +02:00
|
|
|
|
2023-12-21 03:28:21 +02:00
|
|
|
bool ShowOverlay() const { return false; }
|
2019-08-14 14:55:31 +02:00
|
|
|
void ShowOverlay(bool state) {}
|
|
|
|
|
|
|
|
void SetLobbyInvite(Friend friendId, uint64 lobbyId) {}
|
|
|
|
void SetRichInvite(Friend friendId, const char* connect_str) {}
|
|
|
|
|
|
|
|
void FriendConnect(Friend _friend) {}
|
|
|
|
void FriendDisconnect(Friend _friend) {}
|
2019-10-15 19:08:14 +02:00
|
|
|
|
|
|
|
void AddAchievementNotification(nlohmann::json const& ach) {}
|
2019-08-14 14:55:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
#endif//__INCLUDED_STEAM_OVERLAY_H__
|