diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index c8d1a33..597e0b4 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -34,6 +34,19 @@ struct File_Data { std::string name; }; +std::string convert_vector_image_pixel_t_to_std_string(std::vector & in) { + std::string out; + + for (auto i : in) { + out += i.channels.r; + out += i.channels.g; + out += i.channels.b; + out += i.channels.a; + } + + return out; +} + #ifdef NO_DISK_WRITES std::string Local_Storage::get_program_path() { @@ -807,6 +820,10 @@ std::vector Local_Storage::load_image(std::string const& image_pa std::copy(img, img + width * height, res.begin()); stbi_image_free(img); + } else { + width = 0; + height = 0; + PRINT_DEBUG("%s %s. reason: %s\n", "Failed to load image at", image_path.c_str(), stbi_failure_reason()); } if (out_width != nullptr) { if (width > 0) { diff --git a/dll/local_storage.h b/dll/local_storage.h index ae7b6aa..7f8e6c9 100644 --- a/dll/local_storage.h +++ b/dll/local_storage.h @@ -41,6 +41,8 @@ struct image_t std::vector pix_map; }; +std::string convert_vector_image_pixel_t_to_std_string(std::vector & in); + class Local_Storage { public: static constexpr auto inventory_storage_folder = "inventory"; diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index 03e094c..bb161a6 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -340,15 +340,32 @@ 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; + { std::string steam_settings_path = local_storage->get_global_settings_path(); std::vector paths = local_storage->get_filenames_path(steam_settings_path); for (auto & p: paths) { + PRINT_DEBUG("global settings path %s\n", p.c_str()); if (p == "enable_achievement_desc_on_unlock.txt") { enable_achievement_desc_on_unlock = true; } else if (p == "enable_displaying_hidden_achievements.txt") { enable_displaying_hidden_achievements = true; + } else if (p == "profile_small.jpg") { + profile_small.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_small.width, &profile_small.height)); + } else if (p == "profile_medium.jpg") { + profile_medium.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_medium.width, &profile_medium.height)); + } else if (p == "profile_large.jpg") { + profile_large.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_large.width, &profile_large.height)); + } else if (p == "profile_small.png") { + profile_small.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_small.width, &profile_small.height)); + } else if (p == "profile_medium.png") { + profile_medium.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_medium.width, &profile_medium.height)); + } else if (p == "profile_large.png") { + profile_large.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_large.width, &profile_large.height)); } } } @@ -433,6 +450,24 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s settings_server->set_show_achievement_desc_on_unlock(enable_achievement_desc_on_unlock); settings_client->set_show_achievement_hidden_unearned(enable_displaying_hidden_achievements); settings_server->set_show_achievement_hidden_unearned(enable_displaying_hidden_achievements); + if (profile_small.data.length() > 0 && profile_small.width > 0 && profile_small.height > 0) { + settings_client->set_profile_image(k_EAvatarSize32x32, &profile_small); + settings_server->set_profile_image(k_EAvatarSize32x32, &profile_small); + } else { + PRINT_DEBUG("%s %"PRI_ZU" %d %d\n", "Small user profile image not defined.", profile_small.data.length(), profile_small.width, profile_small.height); + } + if (profile_medium.data.length() > 0 && profile_medium.width > 0 && profile_medium.height > 0) { + settings_client->set_profile_image(k_EAvatarSize64x64, &profile_medium); + settings_server->set_profile_image(k_EAvatarSize64x64, &profile_medium); + } else { + PRINT_DEBUG("%s %"PRI_ZU" %d %d\n", "Medium user profile image not defined.", profile_medium.data.length(), profile_medium.width, profile_medium.height); + } + if (profile_large.data.length() > 0 && profile_large.width > 0 && profile_large.height > 0) { + settings_client->set_profile_image(k_EAvatarSize184x184, &profile_large); + settings_server->set_profile_image(k_EAvatarSize184x184, &profile_large); + } else { + PRINT_DEBUG("%s %"PRI_ZU" %d %d\n", "Large user profile image not defined.", profile_large.data.length(), profile_large.width, profile_large.height); + } { std::string dlc_config_path = Local_Storage::get_game_settings_path() + "DLC.txt"; diff --git a/dll/steam_utils.h b/dll/steam_utils.h index b473d54..9a0eb2c 100644 --- a/dll/steam_utils.h +++ b/dll/steam_utils.h @@ -116,7 +116,10 @@ bool GetImageRGBA( int iImage, uint8 *pubDest, int nDestBufferSize ) if (image == settings->images.end()) return false; unsigned size = image->second.data.size(); - if (nDestBufferSize < size) size = nDestBufferSize; + if (nDestBufferSize < size) { + size = nDestBufferSize; + PRINT_DEBUG("GetImageRGBA %i Given buffer too small. Got 0x%x bytes. Need 0x%x bytes.", iImage, nDestBufferSize, size); + } image->second.data.copy((char *)pubDest, nDestBufferSize); return true; }