overlays: Look for the overlay in the same dir as the background

This commit is contained in:
Megamouse 2025-03-20 20:47:27 +01:00
parent 6fb0e991ea
commit 1ae1288a88
3 changed files with 41 additions and 20 deletions

View file

@ -362,22 +362,25 @@ namespace rsx
if (!background_image)
{
game_content_type background_content_type = game_content_type::background_picture;
// Search for any useable background picture in the given order
game_content_type content_type = game_content_type::background_picture;
game_content_dir_type dir_type = game_content_dir_type::any;
for (game_content_type type : { game_content_type::background_picture, game_content_type::content_icon, game_content_type::overlay_picture })
{
if (const std::string picture_path = rpcs3::utils::get_game_content_path(type); fs::is_file(picture_path))
if (const std::string picture_path = rpcs3::utils::get_game_content_path(type, dir_type); !picture_path.empty())
{
background_content_type = type;
content_type = type;
background_image = std::make_unique<image_info>(picture_path);
dirty |= !!background_image->get_data();
break;
}
}
if (background_image && !background_overlay_image && background_content_type == game_content_type::background_picture)
// Search for an overlay picture in the same dir in case we found a real background picture
if (background_image && !background_overlay_image && content_type == game_content_type::background_picture && dir_type != game_content_dir_type::any)
{
if (const std::string picture_path = rpcs3::utils::get_game_content_path(game_content_type::overlay_picture); fs::is_file(picture_path))
if (const std::string picture_path = rpcs3::utils::get_game_content_path(game_content_type::overlay_picture, dir_type); !picture_path.empty())
{
background_overlay_image = std::make_unique<image_info>(picture_path);
dirty |= !!background_overlay_image->get_data();

View file

@ -340,7 +340,7 @@ namespace rpcs3::utils
return get_input_config_dir(title_id) + g_cfg_input_configs.default_config + ".yml";
}
std::string get_game_content_path(game_content_type type)
std::string get_game_content_path(game_content_type type, game_content_dir_type& dir_type)
{
const std::string locale_suffix = fmt::format("_%02d", static_cast<s32>(g_cfg.sys.language.get()));
const std::string disc_dir = vfs::get("/dev_bdvd/PS3_GAME");
@ -352,11 +352,12 @@ namespace rpcs3::utils
}
const bool is_disc_game = !disc_dir.empty();
const bool check_disc = is_disc_game && dir_type != game_content_dir_type::dev_hdd0;
const auto find_content = [is_disc_game, &hdd0_dir, &disc_dir, &locale_suffix](const std::string& name, const std::string& extension) -> std::string
const auto find_content = [&](const std::string& name, const std::string& extension) -> std::string
{
// ICON0.PNG is not supposed to be updateable, so we can ignore the hdd0 dir for disc games in that case
const bool check_hdd0 = !hdd0_dir.empty() && !(is_disc_game && name == "ICON0");
const bool check_hdd0 = !hdd0_dir.empty() && dir_type != game_content_dir_type::dev_bdvd && !(is_disc_game && name == "ICON0");
// Check localized content first
for (bool localized : { true, false })
@ -367,16 +368,24 @@ namespace rpcs3::utils
if (check_hdd0)
{
if (std::string path = hdd0_dir + filename; fs::is_file(path))
{
dir_type = game_content_dir_type::dev_hdd0;
return path;
}
}
// Check content on disc
if (is_disc_game)
if (check_disc)
{
if (std::string path = disc_dir + filename; fs::is_file(path))
{
dir_type = game_content_dir_type::dev_bdvd;
return path;
}
}
}
dir_type = game_content_dir_type::any;
return {};
};
@ -400,20 +409,21 @@ namespace rpcs3::utils
return find_content(high_res ? "PIC0" : "PIC2", "PNG");
}
case game_content_type::background_picture:
case game_content_type::background_picture_2:
{
// Try to find a custom background first
if (std::string path = fs::get_config_dir() + "/Icons/game_icons/" + Emu.GetTitleID() + "/PIC1.PNG"; fs::is_file(path))
{
dir_type = game_content_dir_type::any;
return path;
}
// Look for proper background
if (std::string path = find_content("PIC1", "PNG"); !path.empty())
return path;
// Fallback to PIC3.PNG (should only exist for content discs though...)
return find_content("PIC3", "PNG");
return find_content(type == game_content_type::background_picture ? "PIC1" : "PIC3", "PNG");
}
}
dir_type = game_content_dir_type::any;
return {};
}
}

View file

@ -3,6 +3,13 @@
#include "util/types.hpp"
#include <string>
enum class game_content_dir_type
{
any, // Can also be used as none when returned
dev_hdd0, // HDD0 dir
dev_bdvd, // Disc dir
};
enum class game_content_type
{
content_icon, // ICON0.PNG
@ -10,6 +17,7 @@ enum class game_content_type
content_sound, // SND0.AT3
overlay_picture, // PIC0.PNG (16:9) or PIC2.PNG (4:3)
background_picture, // PIC1.PNG
background_picture_2, // PIC3.PNG (should only exist for install or extra content discs...)
};
namespace rpcs3::utils
@ -40,5 +48,5 @@ namespace rpcs3::utils
std::string get_input_config_dir(const std::string& title_id = "");
std::string get_custom_input_config_path(const std::string& title_id);
std::string get_game_content_path(game_content_type type);
std::string get_game_content_path(game_content_type type, game_content_dir_type& dir_type);
}