mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator
synced 2025-05-23 21:57:40 +08:00
Fix overlay when avatar images are not configured.
(Otherwise, we'll crash after generating too many images.)
This commit is contained in:
parent
4083408bcb
commit
9f4cc05f2a
@ -45,6 +45,8 @@ Settings::Settings(CSteamID steam_id, CGameID game_id, std::string name, std::st
|
||||
this->name = this->name + " ";
|
||||
}
|
||||
|
||||
this->settings_parser_done = false;
|
||||
|
||||
this->ui_notification_position = "";
|
||||
|
||||
auto lang = sanitize(language);
|
||||
@ -465,6 +467,44 @@ int Settings::set_profile_image(int eAvatarSize, Image_Data * image)
|
||||
return ref;
|
||||
}
|
||||
|
||||
int Settings::set_profile_image(int eAvatarSize, int reference, bool notify = true)
|
||||
{
|
||||
bool size_ok = false;
|
||||
int ref = 0;
|
||||
std::lock_guard<std::recursive_mutex> lock(images_mutex);
|
||||
auto t = images.find(reference);
|
||||
if (reference != 0 &&
|
||||
t != images.end()) {
|
||||
ref = t->first;
|
||||
if (eAvatarSize == k_EAvatarSize32x32 && t->second.width > 0 && t->second.width <= 32 && t->second.height > 0 && t->second.height <= 32)
|
||||
size_ok = true;
|
||||
if (eAvatarSize == k_EAvatarSize64x64 && t->second.width > 32 && t->second.width <= 64 && t->second.height > 32 && t->second.height <= 64)
|
||||
size_ok = true;
|
||||
if (eAvatarSize == k_EAvatarSize184x184 && t->second.width > 64 && t->second.width <= 184 && t->second.height > 64 && t->second.height <= 184)
|
||||
size_ok = true;
|
||||
|
||||
if (size_ok == true) {
|
||||
PRINT_DEBUG("Settings::set_profile_image %d -> %d.\n", eAvatarSize, ref);
|
||||
profile_images[eAvatarSize] = ref;
|
||||
if (notify == true) {
|
||||
create_background_notify_task(Settings_Background_Task_IDs::NOTIFY_AVATAR_IMAGE, NULL);
|
||||
}
|
||||
} else {
|
||||
PRINT_DEBUG("%s %d ref: %d.\n",
|
||||
"Settings::set_profile_image failed invalid size. size:",
|
||||
eAvatarSize,
|
||||
reference);
|
||||
}
|
||||
} else {
|
||||
PRINT_DEBUG("%s %d ref: %d.\n",
|
||||
"Settings::set_profile_image failed invalid reference. size:",
|
||||
eAvatarSize,
|
||||
reference);
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
void Settings::set_preferred_network_image_type(int new_type)
|
||||
{
|
||||
switch (new_type) {
|
||||
|
@ -84,6 +84,7 @@ class Settings {
|
||||
std::vector<Settings_Background_Task> background_tasks;
|
||||
std::thread background_monitor_thread;
|
||||
std::recursive_mutex background_thread_mutex;
|
||||
std::atomic<bool> settings_parser_done;
|
||||
|
||||
bool unlockAllDLCs;
|
||||
bool offline;
|
||||
@ -128,6 +129,9 @@ public:
|
||||
uint16 get_port() {return port;}
|
||||
void set_port(uint16 port) { this->port = port;}
|
||||
|
||||
bool is_settings_parser_done() { return this->settings_parser_done; }
|
||||
void set_settings_parser_done(const bool done) { this->settings_parser_done = done; }
|
||||
|
||||
//DLC stuff
|
||||
void unlockAllDLC(bool value);
|
||||
void addDLC(AppId_t appID, std::string name, bool available);
|
||||
@ -176,6 +180,7 @@ public:
|
||||
int get_image(int ref, std::string * data, uint32 * width, uint32 * height);
|
||||
int get_profile_image(int eAvatarSize);
|
||||
int set_profile_image(int eAvatarSize, Image_Data * image);
|
||||
int set_profile_image(int eAvatarSize, int reference, bool notify);
|
||||
int get_preferred_network_image_type() { return this->preferred_network_image_type; }
|
||||
void set_preferred_network_image_type(int new_type);
|
||||
|
||||
|
@ -347,9 +347,9 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
|
||||
|
||||
bool warn_forced = false;
|
||||
|
||||
Image_Data profile_small;
|
||||
Image_Data profile_medium;
|
||||
Image_Data profile_large;
|
||||
Image_Data profile_small {0, 0, std::string()};
|
||||
Image_Data profile_medium {0, 0, std::string()};
|
||||
Image_Data profile_large {0, 0, std::string()};
|
||||
|
||||
{
|
||||
std::string steam_settings_path = local_storage->get_global_settings_path();
|
||||
@ -731,6 +731,9 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
|
||||
|
||||
load_gamecontroller_settings(settings_client);
|
||||
|
||||
settings_client->set_settings_parser_done(true);
|
||||
settings_server->set_settings_parser_done(true);
|
||||
|
||||
*settings_client_out = settings_client;
|
||||
*settings_server_out = settings_server;
|
||||
*local_storage_out = local_storage;
|
||||
|
@ -96,13 +96,24 @@ bool isAppIdCompatible(Friend *f)
|
||||
}
|
||||
|
||||
void generate_avatar_numbers(struct Avatar_Numbers & nums) {
|
||||
std::string small_avatar(32 * 32 * 4, 0);
|
||||
std::string medium_avatar(64 * 64 * 4, 0);
|
||||
std::string large_avatar(184 * 184 * 4, 0);
|
||||
static struct Avatar_Numbers blanks;
|
||||
|
||||
nums.smallest = settings->add_image(small_avatar, 32, 32);
|
||||
nums.medium = settings->add_image(medium_avatar, 64, 64);
|
||||
nums.large = settings->add_image(large_avatar, 184, 184);
|
||||
if (blanks.smallest == 0) {
|
||||
std::string small_avatar(32 * 32 * 4, 0);
|
||||
blanks.smallest = settings->add_image(small_avatar, 32, 32);
|
||||
}
|
||||
if (blanks.medium == 0) {
|
||||
std::string medium_avatar(64 * 64 * 4, 0);
|
||||
blanks.medium = settings->add_image(medium_avatar, 64, 64);
|
||||
}
|
||||
if (blanks.large == 0) {
|
||||
std::string large_avatar(184 * 184 * 4, 0);
|
||||
blanks.large = settings->add_image(large_avatar, 184, 184);
|
||||
}
|
||||
|
||||
nums.smallest = blanks.smallest;
|
||||
nums.medium = blanks.medium;
|
||||
nums.large = blanks.large;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -113,6 +124,13 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id)
|
||||
auto avatar_ids = avatars.find(steam_id);
|
||||
bool generate = true;
|
||||
struct Avatar_Numbers avatar_numbers;
|
||||
|
||||
if (settings->is_settings_parser_done() == false) {
|
||||
do {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
} while (settings->is_settings_parser_done() == false);
|
||||
}
|
||||
|
||||
if (settings->get_local_steam_id().ConvertToUint64() == steam_id) {
|
||||
avatar_numbers.smallest = settings->get_profile_image(k_EAvatarSize32x32);
|
||||
avatar_numbers.medium = settings->get_profile_image(k_EAvatarSize64x64);
|
||||
@ -194,12 +212,17 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id)
|
||||
}
|
||||
|
||||
PRINT_DEBUG("%s %s %s %" PRIu64 ".\n",
|
||||
"Steam_Friends::add_friend_avatars ",
|
||||
"Steam_Friends::add_friend_avatars",
|
||||
(generate == true) ? "Generating empty" : "Notifying changed",
|
||||
"avatar image for",
|
||||
steam_id);
|
||||
if (generate == true) {
|
||||
generate_avatar_numbers(avatar_numbers);
|
||||
if (settings->get_local_steam_id().ConvertToUint64() == steam_id) {
|
||||
settings->set_profile_image(k_EAvatarSize32x32, avatar_numbers.smallest, false);
|
||||
settings->set_profile_image(k_EAvatarSize64x64, avatar_numbers.medium, false);
|
||||
settings->set_profile_image(k_EAvatarSize184x184, avatar_numbers.large, false);
|
||||
}
|
||||
}
|
||||
|
||||
avatar_numbers.last_update_time = std::chrono::steady_clock::now();
|
||||
@ -212,16 +235,9 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id)
|
||||
AvatarImageLoaded_t ail_data = {};
|
||||
bool sent_ail = false;
|
||||
|
||||
auto image = settings->images.find(avatar_numbers.smallest);
|
||||
if (image != settings->images.end()) {
|
||||
width = image->second.width;
|
||||
height = image->second.height;
|
||||
} else {
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
auto image = settings->get_image(avatar_numbers.smallest, NULL, &width, &height);
|
||||
|
||||
if (avatar_numbers.smallest) {
|
||||
if (image == avatar_numbers.smallest) {
|
||||
ail_data.m_steamID = steam_id;
|
||||
ail_data.m_iImage = avatar_numbers.smallest;
|
||||
ail_data.m_iWide = width;
|
||||
@ -230,16 +246,9 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id)
|
||||
sent_ail = true;
|
||||
}
|
||||
|
||||
image = settings->images.find(avatar_numbers.medium);
|
||||
if (image != settings->images.end()) {
|
||||
width = image->second.width;
|
||||
height = image->second.height;
|
||||
} else {
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
image = settings->get_image(avatar_numbers.medium, NULL, &width, &height);
|
||||
|
||||
if (avatar_numbers.medium) {
|
||||
if (image == avatar_numbers.medium) {
|
||||
ail_data.m_steamID = steam_id;
|
||||
ail_data.m_iImage = avatar_numbers.medium;
|
||||
ail_data.m_iWide = width;
|
||||
@ -248,16 +257,9 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id)
|
||||
sent_ail = true;
|
||||
}
|
||||
|
||||
image = settings->images.find(avatar_numbers.large);
|
||||
if (image != settings->images.end()) {
|
||||
width = image->second.width;
|
||||
height = image->second.height;
|
||||
} else {
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
image = settings->get_image(avatar_numbers.large, NULL, &width, &height);
|
||||
|
||||
if (avatar_numbers.large) {
|
||||
if (image == avatar_numbers.large) {
|
||||
ail_data.m_steamID = steam_id;
|
||||
ail_data.m_iImage = avatar_numbers.large;
|
||||
ail_data.m_iWide = width;
|
||||
|
@ -1465,14 +1465,26 @@ int LoadWindowsFontFromMem(const LOGFONT *lf)
|
||||
} else {
|
||||
PRINT_DEBUG("%s %s. otmfsType data: %d.\n", "Licensing failure. Cannot use font", lf->lfFaceName, metric->otmfsType);
|
||||
}
|
||||
} else {
|
||||
PRINT_DEBUG("%s %s.\n",
|
||||
"Steam_Overlay::LoadWindowsFontFromMem GetOutlineTextMetrics() (fill font metric struct) failed for",
|
||||
lf->lfFaceName);
|
||||
}
|
||||
|
||||
free(metric);
|
||||
metric = NULL;
|
||||
}
|
||||
} else {
|
||||
PRINT_DEBUG("%s %s.\n",
|
||||
"Steam_Overlay::LoadWindowsFontFromMem GetOutlineTextMetrics() (get struct size) failed for",
|
||||
lf->lfFaceName);
|
||||
}
|
||||
SelectObject(CBSTR.hDevice, oldFont);
|
||||
DeleteObject(hFont);
|
||||
} else {
|
||||
PRINT_DEBUG("%s %s.\n",
|
||||
"Steam_Overlay::LoadWindowsFontFromMem CreateFontIndirect() failed for",
|
||||
lf->lfFaceName);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -1693,7 +1705,7 @@ void Steam_Overlay::CreateFonts()
|
||||
|
||||
DeleteDC(CBSTR.hDevice); // Order is important.
|
||||
DeleteObject(hBitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
ReleaseDC(oWND, oDC);
|
||||
#else
|
||||
@ -2099,7 +2111,7 @@ int Steam_Overlay::display_imgui_image(uint32_t displayImageType,
|
||||
"for user",
|
||||
userID.ConvertToUint64(),
|
||||
". Load OK.");
|
||||
} else{
|
||||
} else {
|
||||
PRINT_DEBUG("%s %d %s %" PRIu64 " %s\n",
|
||||
"Steam_Overlay::display_imgui_image Unable to get avatar image size",
|
||||
eAvatarSize,
|
||||
|
Loading…
x
Reference in New Issue
Block a user