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->name = this->name + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->settings_parser_done = false;
|
||||||
|
|
||||||
this->ui_notification_position = "";
|
this->ui_notification_position = "";
|
||||||
|
|
||||||
auto lang = sanitize(language);
|
auto lang = sanitize(language);
|
||||||
@ -465,6 +467,44 @@ int Settings::set_profile_image(int eAvatarSize, Image_Data * image)
|
|||||||
return ref;
|
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)
|
void Settings::set_preferred_network_image_type(int new_type)
|
||||||
{
|
{
|
||||||
switch (new_type) {
|
switch (new_type) {
|
||||||
|
@ -84,6 +84,7 @@ class Settings {
|
|||||||
std::vector<Settings_Background_Task> background_tasks;
|
std::vector<Settings_Background_Task> background_tasks;
|
||||||
std::thread background_monitor_thread;
|
std::thread background_monitor_thread;
|
||||||
std::recursive_mutex background_thread_mutex;
|
std::recursive_mutex background_thread_mutex;
|
||||||
|
std::atomic<bool> settings_parser_done;
|
||||||
|
|
||||||
bool unlockAllDLCs;
|
bool unlockAllDLCs;
|
||||||
bool offline;
|
bool offline;
|
||||||
@ -128,6 +129,9 @@ public:
|
|||||||
uint16 get_port() {return port;}
|
uint16 get_port() {return port;}
|
||||||
void set_port(uint16 port) { this->port = 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
|
//DLC stuff
|
||||||
void unlockAllDLC(bool value);
|
void unlockAllDLC(bool value);
|
||||||
void addDLC(AppId_t appID, std::string name, bool available);
|
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_image(int ref, std::string * data, uint32 * width, uint32 * height);
|
||||||
int get_profile_image(int eAvatarSize);
|
int get_profile_image(int eAvatarSize);
|
||||||
int set_profile_image(int eAvatarSize, Image_Data * image);
|
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; }
|
int get_preferred_network_image_type() { return this->preferred_network_image_type; }
|
||||||
void set_preferred_network_image_type(int new_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;
|
bool warn_forced = false;
|
||||||
|
|
||||||
Image_Data profile_small;
|
Image_Data profile_small {0, 0, std::string()};
|
||||||
Image_Data profile_medium;
|
Image_Data profile_medium {0, 0, std::string()};
|
||||||
Image_Data profile_large;
|
Image_Data profile_large {0, 0, std::string()};
|
||||||
|
|
||||||
{
|
{
|
||||||
std::string steam_settings_path = local_storage->get_global_settings_path();
|
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);
|
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_client_out = settings_client;
|
||||||
*settings_server_out = settings_server;
|
*settings_server_out = settings_server;
|
||||||
*local_storage_out = local_storage;
|
*local_storage_out = local_storage;
|
||||||
|
@ -96,13 +96,24 @@ bool isAppIdCompatible(Friend *f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void generate_avatar_numbers(struct Avatar_Numbers & nums) {
|
void generate_avatar_numbers(struct Avatar_Numbers & nums) {
|
||||||
std::string small_avatar(32 * 32 * 4, 0);
|
static struct Avatar_Numbers blanks;
|
||||||
std::string medium_avatar(64 * 64 * 4, 0);
|
|
||||||
std::string large_avatar(184 * 184 * 4, 0);
|
|
||||||
|
|
||||||
nums.smallest = settings->add_image(small_avatar, 32, 32);
|
if (blanks.smallest == 0) {
|
||||||
nums.medium = settings->add_image(medium_avatar, 64, 64);
|
std::string small_avatar(32 * 32 * 4, 0);
|
||||||
nums.large = settings->add_image(large_avatar, 184, 184);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +124,13 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id)
|
|||||||
auto avatar_ids = avatars.find(steam_id);
|
auto avatar_ids = avatars.find(steam_id);
|
||||||
bool generate = true;
|
bool generate = true;
|
||||||
struct Avatar_Numbers avatar_numbers;
|
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) {
|
if (settings->get_local_steam_id().ConvertToUint64() == steam_id) {
|
||||||
avatar_numbers.smallest = settings->get_profile_image(k_EAvatarSize32x32);
|
avatar_numbers.smallest = settings->get_profile_image(k_EAvatarSize32x32);
|
||||||
avatar_numbers.medium = settings->get_profile_image(k_EAvatarSize64x64);
|
avatar_numbers.medium = settings->get_profile_image(k_EAvatarSize64x64);
|
||||||
@ -200,6 +218,11 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id)
|
|||||||
steam_id);
|
steam_id);
|
||||||
if (generate == true) {
|
if (generate == true) {
|
||||||
generate_avatar_numbers(avatar_numbers);
|
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();
|
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 = {};
|
AvatarImageLoaded_t ail_data = {};
|
||||||
bool sent_ail = false;
|
bool sent_ail = false;
|
||||||
|
|
||||||
auto image = settings->images.find(avatar_numbers.smallest);
|
auto image = settings->get_image(avatar_numbers.smallest, NULL, &width, &height);
|
||||||
if (image != settings->images.end()) {
|
|
||||||
width = image->second.width;
|
|
||||||
height = image->second.height;
|
|
||||||
} else {
|
|
||||||
width = 0;
|
|
||||||
height = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (avatar_numbers.smallest) {
|
if (image == avatar_numbers.smallest) {
|
||||||
ail_data.m_steamID = steam_id;
|
ail_data.m_steamID = steam_id;
|
||||||
ail_data.m_iImage = avatar_numbers.smallest;
|
ail_data.m_iImage = avatar_numbers.smallest;
|
||||||
ail_data.m_iWide = width;
|
ail_data.m_iWide = width;
|
||||||
@ -230,16 +246,9 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id)
|
|||||||
sent_ail = true;
|
sent_ail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
image = settings->images.find(avatar_numbers.medium);
|
image = settings->get_image(avatar_numbers.medium, NULL, &width, &height);
|
||||||
if (image != settings->images.end()) {
|
|
||||||
width = image->second.width;
|
|
||||||
height = image->second.height;
|
|
||||||
} else {
|
|
||||||
width = 0;
|
|
||||||
height = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (avatar_numbers.medium) {
|
if (image == avatar_numbers.medium) {
|
||||||
ail_data.m_steamID = steam_id;
|
ail_data.m_steamID = steam_id;
|
||||||
ail_data.m_iImage = avatar_numbers.medium;
|
ail_data.m_iImage = avatar_numbers.medium;
|
||||||
ail_data.m_iWide = width;
|
ail_data.m_iWide = width;
|
||||||
@ -248,16 +257,9 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id)
|
|||||||
sent_ail = true;
|
sent_ail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
image = settings->images.find(avatar_numbers.large);
|
image = settings->get_image(avatar_numbers.large, NULL, &width, &height);
|
||||||
if (image != settings->images.end()) {
|
|
||||||
width = image->second.width;
|
|
||||||
height = image->second.height;
|
|
||||||
} else {
|
|
||||||
width = 0;
|
|
||||||
height = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (avatar_numbers.large) {
|
if (image == avatar_numbers.large) {
|
||||||
ail_data.m_steamID = steam_id;
|
ail_data.m_steamID = steam_id;
|
||||||
ail_data.m_iImage = avatar_numbers.large;
|
ail_data.m_iImage = avatar_numbers.large;
|
||||||
ail_data.m_iWide = width;
|
ail_data.m_iWide = width;
|
||||||
|
@ -1465,14 +1465,26 @@ int LoadWindowsFontFromMem(const LOGFONT *lf)
|
|||||||
} else {
|
} else {
|
||||||
PRINT_DEBUG("%s %s. otmfsType data: %d.\n", "Licensing failure. Cannot use font", lf->lfFaceName, metric->otmfsType);
|
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);
|
free(metric);
|
||||||
metric = NULL;
|
metric = NULL;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
PRINT_DEBUG("%s %s.\n",
|
||||||
|
"Steam_Overlay::LoadWindowsFontFromMem GetOutlineTextMetrics() (get struct size) failed for",
|
||||||
|
lf->lfFaceName);
|
||||||
}
|
}
|
||||||
SelectObject(CBSTR.hDevice, oldFont);
|
SelectObject(CBSTR.hDevice, oldFont);
|
||||||
DeleteObject(hFont);
|
DeleteObject(hFont);
|
||||||
|
} else {
|
||||||
|
PRINT_DEBUG("%s %s.\n",
|
||||||
|
"Steam_Overlay::LoadWindowsFontFromMem CreateFontIndirect() failed for",
|
||||||
|
lf->lfFaceName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user