2019-07-31 20:21:02 +00:00
|
|
|
#include "steam_overlay.h"
|
|
|
|
|
2019-08-14 12:55:31 +00:00
|
|
|
#ifdef STEAM_WIN32
|
|
|
|
|
2019-07-31 20:21:02 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2019-08-03 10:58:48 +00:00
|
|
|
#include <cctype>
|
2019-07-31 20:21:02 +00:00
|
|
|
#include <imgui.h>
|
|
|
|
#include <impls/imgui_impl_win32.h>
|
|
|
|
|
2019-08-01 09:35:36 +00:00
|
|
|
#include "../dll/dll.h"
|
2019-07-31 20:21:02 +00:00
|
|
|
|
2019-08-12 14:04:14 +00:00
|
|
|
// Get all steam appid with their name: http://api.steampowered.com/ISteamApps/GetAppList/v2/
|
|
|
|
// Steam storefront webapi: https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI
|
|
|
|
// http://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v2/?key=27FB0BB1A97A95244C5E08B170A54F96&appid=218620
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
"game" : {
|
|
|
|
"gameName" : "<name>",
|
|
|
|
"availableGameStats" : {
|
|
|
|
"achievements" : {
|
|
|
|
("<id>" : {
|
|
|
|
"name" : "achievement_name",
|
|
|
|
"displayName" : "achievement name on screen",
|
|
|
|
"hidden" : (0|1),
|
|
|
|
"description" : "<desc>",
|
|
|
|
"icon" : "<url to icon when achievement is earned>",
|
|
|
|
"icongray" : "<url to icon when achievement is not earned>"
|
|
|
|
},
|
|
|
|
...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// Get appid infos: http://store.steampowered.com/api/appdetails/?appids=218620
|
|
|
|
/*
|
|
|
|
"appid" : {
|
|
|
|
"success" : (true|false),
|
|
|
|
(success == true "data" : {
|
|
|
|
...
|
|
|
|
"name" : "<name>",
|
|
|
|
"steam_appid" : <appid>,
|
|
|
|
(OPT "dlc" : [<dlc id>, <dlc id>]),
|
|
|
|
"header_image" : "<miniature url>" <-- Use this in the overlay ?
|
|
|
|
(OPT "achievements" : {
|
|
|
|
"total" : <num of achievements>
|
|
|
|
}),
|
|
|
|
"background" : "<background url>" <-- Use this as the overlay background ?
|
|
|
|
(OPT "packages" : [<package id>, <package id>])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2019-07-31 20:21:02 +00:00
|
|
|
extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
|
|
|
2019-08-07 09:11:31 +00:00
|
|
|
bool Steam_Overlay::IgnoreMsg(UINT uMsg)
|
2019-07-31 20:21:02 +00:00
|
|
|
{
|
2019-08-07 09:11:31 +00:00
|
|
|
switch (uMsg)
|
2019-08-06 11:46:43 +00:00
|
|
|
{
|
2019-08-07 09:11:31 +00:00
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
case WM_MOUSEWHEEL: case WM_MOUSEHWHEEL:
|
|
|
|
case WM_LBUTTONUP: case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK:
|
|
|
|
case WM_RBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK:
|
|
|
|
case WM_MBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK:
|
|
|
|
case WM_XBUTTONUP: case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK:
|
|
|
|
case WM_KEYDOWN: case WM_KEYUP:
|
|
|
|
case WM_SYSKEYDOWN: case WM_SYSKEYUP:
|
|
|
|
case WM_CHAR:
|
|
|
|
return true;
|
2019-08-06 11:46:43 +00:00
|
|
|
}
|
|
|
|
return false;
|
2019-07-31 20:21:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 09:11:31 +00:00
|
|
|
LRESULT CALLBACK Steam_Overlay::HookWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2019-07-31 20:21:02 +00:00
|
|
|
{
|
2019-08-07 09:11:31 +00:00
|
|
|
Steam_Overlay* _this = Hook_Manager::Inst().GetOverlay();
|
2019-07-31 20:21:02 +00:00
|
|
|
// Is the event is a key press
|
|
|
|
if (uMsg == WM_KEYDOWN)
|
|
|
|
{
|
|
|
|
// Tab is pressed and was not pressed before
|
|
|
|
if (wParam == VK_TAB && !(lParam & (1 << 30)))
|
|
|
|
{
|
|
|
|
// If Left Shift is pressed
|
|
|
|
if (GetAsyncKeyState(VK_LSHIFT) & (1 << 15))
|
2019-08-07 09:11:31 +00:00
|
|
|
_this->ShowOverlay(!_this->show_overlay);
|
2019-07-31 20:21:02 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-07 09:11:31 +00:00
|
|
|
|
|
|
|
if (_this->show_overlay)
|
2019-07-31 20:21:02 +00:00
|
|
|
{
|
|
|
|
ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam);
|
2019-08-07 09:11:31 +00:00
|
|
|
if (_this->IgnoreMsg(uMsg))
|
|
|
|
return 0;
|
2019-07-31 20:21:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 09:11:31 +00:00
|
|
|
// Call the overlay window procedure
|
|
|
|
return CallWindowProc(_this->game_hwnd_proc, hWnd, uMsg, wParam, lParam);
|
2019-07-31 20:21:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 11:46:43 +00:00
|
|
|
void Steam_Overlay::steam_overlay_run_every_runcb(void* object)
|
|
|
|
{
|
|
|
|
Steam_Overlay* _this = reinterpret_cast<Steam_Overlay*>(object);
|
|
|
|
_this->RunCallbacks();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::steam_overlay_callback(void* object, Common_Message* msg)
|
|
|
|
{
|
|
|
|
Steam_Overlay* _this = reinterpret_cast<Steam_Overlay*>(object);
|
|
|
|
_this->Callback(msg);
|
|
|
|
}
|
|
|
|
|
2019-07-31 20:21:02 +00:00
|
|
|
Steam_Overlay::Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking *network) :
|
|
|
|
settings(settings),
|
|
|
|
callback_results(callback_results),
|
|
|
|
callbacks(callbacks),
|
|
|
|
run_every_runcb(run_every_runcb),
|
|
|
|
network(network),
|
|
|
|
game_hwnd(NULL),
|
|
|
|
game_hwnd_proc(nullptr),
|
|
|
|
show_overlay(false),
|
|
|
|
is_ready(false),
|
|
|
|
notif_position(ENotificationPosition::k_EPositionBottomLeft),
|
|
|
|
h_inset(0),
|
|
|
|
v_inset(0),
|
|
|
|
overlay_state_changed(false)
|
|
|
|
{
|
|
|
|
run_every_runcb->add(&Steam_Overlay::steam_overlay_run_every_runcb, this);
|
2019-08-03 10:58:48 +00:00
|
|
|
this->network->setCallback(CALLBACK_ID_STEAM_MESSAGES, settings->get_local_steam_id(), &Steam_Overlay::steam_overlay_callback, this);
|
2019-07-31 20:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Steam_Overlay::~Steam_Overlay()
|
|
|
|
{
|
|
|
|
run_every_runcb->remove(&Steam_Overlay::steam_overlay_run_every_runcb, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND Steam_Overlay::GetGameHwnd() const
|
|
|
|
{
|
|
|
|
return game_hwnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Steam_Overlay::Ready() const
|
|
|
|
{
|
|
|
|
return is_ready;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Steam_Overlay::NeedPresent() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::SetNotificationPosition(ENotificationPosition eNotificationPosition)
|
|
|
|
{
|
|
|
|
notif_position = eNotificationPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::SetNotificationInset(int nHorizontalInset, int nVerticalInset)
|
|
|
|
{
|
|
|
|
h_inset = nHorizontalInset;
|
|
|
|
v_inset = nVerticalInset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::SetupOverlay()
|
|
|
|
{
|
|
|
|
Hook_Manager::Inst().HookRenderer(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::HookReady(void* hWnd)
|
|
|
|
{
|
|
|
|
if (game_hwnd != hWnd)
|
|
|
|
{
|
2019-08-07 09:11:31 +00:00
|
|
|
if (!is_ready) // If this is the first time we are ready, hook directinput and xinput, so we can intercept em and disable mouse.
|
2019-07-31 20:21:02 +00:00
|
|
|
{
|
2019-08-07 09:11:31 +00:00
|
|
|
//window_hooks.BeginHook();
|
|
|
|
//
|
|
|
|
//window_hooks.HookFuncs(std::make_pair<void**, void*>(&(PVOID&)_DispatchMessageA, &Steam_Overlay::MyDispatchMessageA),
|
|
|
|
// std::make_pair<void**, void*>(&(PVOID&)_DispatchMessageW, &Steam_Overlay::MyDispatchMessageW)
|
|
|
|
// // Add XInput and DirectInput hooks to catch all mouse & controllers input when overlay is on
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
//window_hooks.EndHook();
|
2019-07-31 20:21:02 +00:00
|
|
|
|
|
|
|
is_ready = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (game_hwnd)
|
|
|
|
SetWindowLongPtr(game_hwnd, GWLP_WNDPROC, (LONG_PTR)game_hwnd_proc);
|
|
|
|
|
|
|
|
game_hwnd = (HWND)hWnd;
|
2019-08-07 09:11:31 +00:00
|
|
|
game_hwnd_proc = (WNDPROC)SetWindowLongPtr(game_hwnd, GWLP_WNDPROC, (LONG_PTR)&Steam_Overlay::HookWndProc);
|
2019-07-31 20:21:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://niemand.com.ar/2019/01/01/how-to-hook-directx-11-imgui/
|
|
|
|
// https://github.com/spazzarama/Direct3DHook/blob/master/Capture/Hook
|
|
|
|
// https://github.com/unknownv2/LinuxDetours
|
|
|
|
|
|
|
|
void Steam_Overlay::OpenOverlayInvite(CSteamID lobbyId)
|
|
|
|
{
|
2019-08-02 09:16:30 +00:00
|
|
|
ShowOverlay(true);
|
2019-07-31 20:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::OpenOverlay(const char* pchDialog)
|
|
|
|
{
|
|
|
|
// TODO: Show pages depending on pchDialog
|
2019-08-02 09:16:30 +00:00
|
|
|
ShowOverlay(true);
|
2019-07-31 20:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::ShowOverlay(bool state)
|
|
|
|
{
|
|
|
|
static RECT old_clip;
|
|
|
|
|
|
|
|
if (show_overlay == state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
show_overlay = state;
|
|
|
|
if (show_overlay)
|
|
|
|
{
|
|
|
|
RECT cliRect, wndRect, clipRect;
|
|
|
|
|
|
|
|
GetClipCursor(&old_clip);
|
|
|
|
// The window rectangle has borders and menus counted in the size
|
|
|
|
GetWindowRect(game_hwnd, &wndRect);
|
|
|
|
// The client rectangle is the window without borders
|
|
|
|
GetClientRect(game_hwnd, &cliRect);
|
|
|
|
|
|
|
|
clipRect = wndRect; // Init clip rectangle
|
|
|
|
|
|
|
|
// Get Window width with borders
|
|
|
|
wndRect.right -= wndRect.left;
|
|
|
|
// Get Window height with borders & menus
|
|
|
|
wndRect.bottom -= wndRect.top;
|
|
|
|
// Compute the border width
|
|
|
|
int borderWidth = (wndRect.right - cliRect.right) / 2;
|
|
|
|
// Client top clip is the menu bar width minus bottom border
|
|
|
|
clipRect.top += wndRect.bottom - cliRect.bottom - borderWidth;
|
|
|
|
// Client left clip is the left border minus border width
|
|
|
|
clipRect.left += borderWidth;
|
|
|
|
// Here goes the same for right and bottom
|
|
|
|
clipRect.right -= borderWidth;
|
|
|
|
clipRect.bottom -= borderWidth;
|
|
|
|
|
|
|
|
ClipCursor(&clipRect);
|
|
|
|
ImGui::GetIO().MouseDrawCursor = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClipCursor(&old_clip);
|
|
|
|
ImGui::GetIO().MouseDrawCursor = false;
|
|
|
|
}
|
|
|
|
overlay_state_changed = true;
|
|
|
|
}
|
|
|
|
|
2019-08-02 21:01:24 +00:00
|
|
|
void Steam_Overlay::SetLobbyInvite(Friend friendId, uint64 lobbyId)
|
2019-08-02 09:16:30 +00:00
|
|
|
{
|
2019-08-02 11:02:20 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
auto i = friends.find(friendId);
|
|
|
|
if (i != friends.end())
|
|
|
|
{
|
|
|
|
auto& frd = i->second;
|
|
|
|
frd.lobbyId = lobbyId;
|
|
|
|
frd.window_state |= window_state_lobby_invite;
|
2019-08-02 21:01:24 +00:00
|
|
|
// Make sure don't have rich presence invite and a lobby invite (it should not happen but who knows)
|
|
|
|
frd.window_state &= ~window_state_rich_invite;
|
2019-08-02 11:02:20 +00:00
|
|
|
}
|
2019-08-02 09:16:30 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 21:01:24 +00:00
|
|
|
void Steam_Overlay::SetRichInvite(Friend friendId, const char* connect_str)
|
2019-08-02 09:16:30 +00:00
|
|
|
{
|
2019-08-02 11:02:20 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
auto i = friends.find(friendId);
|
|
|
|
if (i != friends.end())
|
|
|
|
{
|
|
|
|
auto& frd = i->second;
|
|
|
|
strncpy(frd.connect, connect_str, k_cchMaxRichPresenceValueLength - 1);
|
|
|
|
frd.window_state |= window_state_rich_invite;
|
2019-08-02 21:01:24 +00:00
|
|
|
// Make sure don't have rich presence invite and a lobby invite (it should not happen but who knows)
|
|
|
|
frd.window_state &= ~window_state_lobby_invite;
|
2019-08-02 11:02:20 +00:00
|
|
|
}
|
2019-08-02 09:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::FriendConnect(Friend _friend)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
2019-08-02 11:02:20 +00:00
|
|
|
friends[_friend].window_state = window_state_none;
|
2019-08-03 10:58:48 +00:00
|
|
|
memset(friends[_friend].chat_input, 0, max_chat_len);
|
2019-08-02 09:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::FriendDisconnect(Friend _friend)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
auto it = friends.find(_friend);
|
|
|
|
if (it != friends.end())
|
|
|
|
friends.erase(it);
|
|
|
|
}
|
|
|
|
|
2019-08-06 11:46:43 +00:00
|
|
|
bool Steam_Overlay::FriendHasLobby(uint64 friend_id)
|
|
|
|
{
|
|
|
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
|
|
|
|
|
|
|
if( std::string(steamFriends->GetFriendRichPresence(friend_id, "connect")).length() > 0 )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
FriendGameInfo_t friend_game_info = {};
|
|
|
|
steamFriends->GetFriendGamePlayed(friend_id, &friend_game_info);
|
|
|
|
if (friend_game_info.m_steamIDLobby.IsValid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Steam_Overlay::IHaveLobby()
|
|
|
|
{
|
|
|
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
|
|
|
if (std::string(steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect")).length() > 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (settings->get_lobby().IsValid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-02 13:26:16 +00:00
|
|
|
void Steam_Overlay::BuildContextMenu(Friend const& frd, friend_window_state& state)
|
|
|
|
{
|
|
|
|
if (ImGui::BeginPopupContextItem("Friends", 1))
|
|
|
|
{
|
2019-08-06 11:46:43 +00:00
|
|
|
bool close_popup = false;
|
|
|
|
|
|
|
|
if (ImGui::Button("Chat"))
|
|
|
|
{
|
|
|
|
state.window_state |= window_state_show;
|
|
|
|
close_popup = true;
|
|
|
|
}
|
|
|
|
if (IHaveLobby() && ImGui::Button("Invite"))
|
2019-08-02 13:26:16 +00:00
|
|
|
{
|
|
|
|
state.window_state |= window_state_invite;
|
|
|
|
has_friend_action.push(frd);
|
2019-08-06 11:46:43 +00:00
|
|
|
close_popup = true;
|
2019-08-02 13:26:16 +00:00
|
|
|
}
|
2019-08-06 11:46:43 +00:00
|
|
|
if (FriendHasLobby(frd.id()) && ImGui::Button("Join"))
|
2019-08-02 13:26:16 +00:00
|
|
|
{
|
|
|
|
state.window_state |= window_state_join;
|
|
|
|
has_friend_action.push(frd);
|
2019-08-06 11:46:43 +00:00
|
|
|
close_popup = true;
|
2019-08-02 13:26:16 +00:00
|
|
|
}
|
2019-08-06 11:46:43 +00:00
|
|
|
|
|
|
|
if( close_popup)
|
|
|
|
{
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
2019-08-02 13:26:16 +00:00
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::BuildFriendWindow(Friend const& frd, friend_window_state& state)
|
|
|
|
{
|
|
|
|
if (!(state.window_state & window_state_show))
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool show = true;
|
2019-08-06 11:46:43 +00:00
|
|
|
bool send_chat_msg = false;
|
2019-08-03 10:58:48 +00:00
|
|
|
|
2019-08-02 13:26:16 +00:00
|
|
|
if (ImGui::Begin(frd.name().c_str(), &show))
|
|
|
|
{
|
|
|
|
// Fill this with the chat box and maybe the invitation
|
|
|
|
if (state.window_state & (window_state_lobby_invite | window_state_rich_invite))
|
|
|
|
{
|
2019-08-03 10:58:48 +00:00
|
|
|
ImGui::LabelText("##label", "%s invited you to join the game.", frd.name().c_str());
|
2019-08-02 13:26:16 +00:00
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::Button("Accept"))
|
|
|
|
{
|
|
|
|
this->has_friend_action.push(frd);
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::Button("Refuse"))
|
|
|
|
{
|
|
|
|
state.window_state &= ~(window_state_lobby_invite | window_state_rich_invite);
|
|
|
|
}
|
|
|
|
}
|
2019-08-03 10:58:48 +00:00
|
|
|
|
|
|
|
ImGui::PushItemWidth(-1.0f);
|
2019-08-03 12:37:03 +00:00
|
|
|
ImGui::ColoredInputTextMultiline("##chat_history", &state.chat_history[0], state.chat_history.length(), { -1.0f, 0 }, ImGuiInputTextFlags_ReadOnly);
|
2019-08-03 10:58:48 +00:00
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
if (ImGui::InputText("##chat_line", state.chat_input, max_chat_len, ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
{
|
2019-08-06 11:46:43 +00:00
|
|
|
send_chat_msg = true;
|
2019-08-03 10:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (ImGui::Button("Send"))
|
2019-08-06 11:46:43 +00:00
|
|
|
{
|
|
|
|
send_chat_msg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (send_chat_msg)
|
2019-08-03 10:58:48 +00:00
|
|
|
{
|
|
|
|
if (!(state.window_state & window_state_send_message))
|
|
|
|
{
|
|
|
|
has_friend_action.push(frd);
|
|
|
|
state.window_state |= window_state_send_message;
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 13:26:16 +00:00
|
|
|
}
|
|
|
|
// User closed the friend window
|
|
|
|
if (!show)
|
|
|
|
state.window_state &= ~window_state_show;
|
2019-08-06 11:46:43 +00:00
|
|
|
|
2019-08-02 13:26:16 +00:00
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2019-07-31 20:21:02 +00:00
|
|
|
void Steam_Overlay::OverlayProc( int width, int height )
|
|
|
|
{
|
|
|
|
if (!show_overlay)
|
|
|
|
return;
|
|
|
|
|
2019-08-02 07:09:32 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
|
2019-08-02 09:16:30 +00:00
|
|
|
int friend_size = friends.size();
|
2019-07-31 20:21:02 +00:00
|
|
|
|
|
|
|
// Set the overlay windows to the size of the game window
|
|
|
|
ImGui::SetNextWindowPos({ 0,0 });
|
|
|
|
ImGui::SetNextWindowSize({ static_cast<float>(width),
|
|
|
|
static_cast<float>(height) });
|
2019-08-07 09:11:31 +00:00
|
|
|
|
|
|
|
ImGui::SetNextWindowBgAlpha(0.50);
|
|
|
|
ImGuiStyle& style = ImGui::GetStyle();
|
|
|
|
style.WindowRounding = 0.0;
|
2019-07-31 20:21:02 +00:00
|
|
|
|
2019-08-03 10:58:48 +00:00
|
|
|
if (ImGui::Begin("SteamOverlay", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus))
|
2019-07-31 20:21:02 +00:00
|
|
|
{
|
2019-08-03 10:58:48 +00:00
|
|
|
ImGui::LabelText("##label", "Username: %s(%llu) playing %u",
|
2019-07-31 20:21:02 +00:00
|
|
|
settings->get_local_name(),
|
|
|
|
settings->get_local_steam_id().ConvertToUint64(),
|
|
|
|
settings->get_local_game_id().AppID());
|
|
|
|
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
2019-08-03 10:58:48 +00:00
|
|
|
ImGui::LabelText("##label", "Friends");
|
|
|
|
ImGui::ListBoxHeader("##label", friend_size);
|
2019-08-02 09:16:30 +00:00
|
|
|
std::for_each(friends.begin(), friends.end(), [this]( auto& i)
|
2019-07-31 20:21:02 +00:00
|
|
|
{
|
2019-08-02 09:16:30 +00:00
|
|
|
ImGui::PushID(i.first.id());
|
2019-08-02 13:26:16 +00:00
|
|
|
|
2019-08-02 09:16:30 +00:00
|
|
|
ImGui::Selectable(i.first.name().c_str(), false, ImGuiSelectableFlags_AllowDoubleClick);
|
2019-08-02 13:26:16 +00:00
|
|
|
BuildContextMenu(i.first, i.second);
|
|
|
|
if (ImGui::IsItemClicked() && ImGui::IsMouseDoubleClicked(0))
|
2019-08-02 09:16:30 +00:00
|
|
|
{
|
2019-08-02 11:02:20 +00:00
|
|
|
i.second.window_state |= window_state_show;
|
2019-08-02 09:16:30 +00:00
|
|
|
}
|
2019-08-02 13:26:16 +00:00
|
|
|
|
2019-08-02 09:16:30 +00:00
|
|
|
ImGui::PopID();
|
|
|
|
|
2019-08-02 13:26:16 +00:00
|
|
|
BuildFriendWindow(i.first, i.second);
|
2019-08-02 09:16:30 +00:00
|
|
|
});
|
2019-07-31 20:21:02 +00:00
|
|
|
ImGui::ListBoxFooter();
|
|
|
|
|
|
|
|
//RECT rect;
|
|
|
|
//GetWindowRect(game_hwnd, &rect);
|
|
|
|
//auto pos = ImGui::GetMousePos();
|
|
|
|
//ImGui::LabelText("", "Window pos: %dx%d %dx%d", rect.left, rect.top, rect.right, rect.bottom);
|
|
|
|
//ImGui::LabelText("", "Mouse pos: %dx%d", (int)pos.x, (int)pos.y);
|
|
|
|
}
|
2019-08-02 09:16:30 +00:00
|
|
|
ImGui::End();
|
|
|
|
|
2019-07-31 20:21:02 +00:00
|
|
|
//ImGui::ShowDemoWindow();
|
|
|
|
}
|
|
|
|
|
2019-08-03 10:58:48 +00:00
|
|
|
void Steam_Overlay::Callback(Common_Message *msg)
|
|
|
|
{
|
|
|
|
if (msg->has_steam_messages())
|
|
|
|
{
|
|
|
|
Friend frd;
|
|
|
|
frd.set_id(msg->source_id());
|
|
|
|
auto friend_info = friends.find(frd);
|
|
|
|
if (friend_info != friends.end())
|
|
|
|
{
|
|
|
|
Steam_Messages const& steam_message = msg->steam_messages();
|
|
|
|
// Change color to cyan for friend
|
|
|
|
friend_info->second.chat_history.append("\x1", 1).append("00FFFFFF", 8).append(steam_message.message()).append("\n", 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 20:21:02 +00:00
|
|
|
void Steam_Overlay::RunCallbacks()
|
|
|
|
{
|
|
|
|
if (overlay_state_changed)
|
|
|
|
{
|
|
|
|
GameOverlayActivated_t data = { 0 };
|
|
|
|
data.m_bActive = show_overlay;
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
|
|
|
|
overlay_state_changed = false;
|
|
|
|
}
|
|
|
|
|
2019-08-01 09:15:38 +00:00
|
|
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
|
|
|
Steam_Matchmaking* steamMatchmaking = get_steam_client()->steam_matchmaking;
|
|
|
|
|
2019-08-02 11:02:20 +00:00
|
|
|
while (!has_friend_action.empty())
|
2019-07-31 20:21:02 +00:00
|
|
|
{
|
2019-08-02 11:02:20 +00:00
|
|
|
auto friend_info = friends.find(has_friend_action.front());
|
|
|
|
if (friend_info != friends.end())
|
|
|
|
{
|
|
|
|
uint64 friend_id = friend_info->first.id();
|
2019-08-06 11:46:43 +00:00
|
|
|
// The user clicked on "Send"
|
2019-08-03 10:58:48 +00:00
|
|
|
if (friend_info->second.window_state & window_state_send_message)
|
|
|
|
{
|
|
|
|
char* input = friend_info->second.chat_input;
|
|
|
|
char* end_input = input + strlen(input);
|
|
|
|
char* printable_char = std::find_if(input, end_input, [](char c) {
|
|
|
|
return std::isgraph(c);
|
|
|
|
});
|
2019-08-06 11:46:43 +00:00
|
|
|
// Check if the message contains something else than blanks
|
2019-08-03 10:58:48 +00:00
|
|
|
if (printable_char != end_input)
|
|
|
|
{
|
|
|
|
// Handle chat send
|
|
|
|
Common_Message msg;
|
|
|
|
Steam_Messages* steam_messages = new Steam_Messages;
|
|
|
|
steam_messages->set_type(Steam_Messages::FRIEND_CHAT);
|
|
|
|
steam_messages->set_message(friend_info->second.chat_input);
|
|
|
|
msg.set_allocated_steam_messages(steam_messages);
|
|
|
|
msg.set_source_id(settings->get_local_steam_id().ConvertToUint64());
|
|
|
|
msg.set_dest_id(friend_id);
|
|
|
|
network->sendTo(&msg, true);
|
|
|
|
|
|
|
|
friend_info->second.chat_history.append("\x1", 1).append("00FF00FF", 8).append(input).append("\n", 1);
|
|
|
|
}
|
|
|
|
*input = 0; // Reset the input field
|
|
|
|
friend_info->second.window_state &= ~window_state_send_message;
|
|
|
|
}
|
2019-08-02 11:02:20 +00:00
|
|
|
// The user clicked on "Invite"
|
|
|
|
if (friend_info->second.window_state & window_state_invite)
|
|
|
|
{
|
|
|
|
std::string connect = steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect");
|
|
|
|
if (connect.length() > 0)
|
|
|
|
steamFriends->InviteUserToGame(friend_id, connect.c_str());
|
|
|
|
else if (settings->get_lobby().IsValid())
|
|
|
|
steamMatchmaking->InviteUserToLobby(settings->get_lobby(), friend_id);
|
2019-07-31 20:21:02 +00:00
|
|
|
|
2019-08-02 11:02:20 +00:00
|
|
|
friend_info->second.window_state &= ~window_state_invite;
|
|
|
|
}
|
|
|
|
// The user clicked on "Join"
|
|
|
|
if (friend_info->second.window_state & window_state_join)
|
|
|
|
{
|
|
|
|
std::string connect = steamFriends->GetFriendRichPresence(friend_id, "connect");
|
|
|
|
if (connect.length() > 0)
|
|
|
|
{
|
|
|
|
GameRichPresenceJoinRequested_t data = {};
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
|
|
|
strncpy(data.m_rgchConnect, connect.c_str(), k_cchMaxRichPresenceValueLength - 1);
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FriendGameInfo_t friend_game_info = {};
|
|
|
|
steamFriends->GetFriendGamePlayed(friend_id, &friend_game_info);
|
|
|
|
if (friend_game_info.m_steamIDLobby.IsValid())
|
|
|
|
steamMatchmaking->JoinLobby(friend_game_info.m_steamIDLobby);
|
|
|
|
}
|
2019-07-31 20:21:02 +00:00
|
|
|
|
2019-08-02 11:02:20 +00:00
|
|
|
friend_info->second.window_state &= ~window_state_join;
|
|
|
|
}
|
2019-08-06 11:46:43 +00:00
|
|
|
// The user got a lobby invite and accepted it
|
2019-08-02 11:02:20 +00:00
|
|
|
if (friend_info->second.window_state & window_state_lobby_invite)
|
|
|
|
{
|
|
|
|
GameLobbyJoinRequested_t data;
|
|
|
|
data.m_steamIDLobby.SetFromUint64(friend_info->second.lobbyId);
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
|
|
|
|
friend_info->second.window_state &= ~window_state_lobby_invite;
|
|
|
|
}
|
2019-08-06 11:46:43 +00:00
|
|
|
// The user got a rich presence invite and accepted it
|
2019-08-02 11:02:20 +00:00
|
|
|
if (friend_info->second.window_state & window_state_rich_invite)
|
|
|
|
{
|
|
|
|
GameRichPresenceJoinRequested_t data = {};
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
|
|
|
strncpy(data.m_rgchConnect, friend_info->second.connect, k_cchMaxRichPresenceValueLength - 1);
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
2019-07-31 20:21:02 +00:00
|
|
|
|
2019-08-02 11:02:20 +00:00
|
|
|
friend_info->second.window_state &= ~window_state_rich_invite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
has_friend_action.pop();
|
2019-07-31 20:21:02 +00:00
|
|
|
}
|
2019-08-14 12:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
* Add here the code for Linux overlay
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endif
|