Skip to content

Commit

Permalink
Fix fake game ID generation to work with scoped storage
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 23, 2024
1 parent 796787d commit 2e16fd3
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 13 deletions.
12 changes: 6 additions & 6 deletions Core/ELF/ParamSFO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ std::vector<std::string> ParamSFOData::GetKeys() const {
std::string ParamSFOData::GetDiscID() {
const std::string discID = GetValueString("DISC_ID");
if (discID.empty()) {
std::string fakeID = GenerateFakeID();
std::string fakeID = GenerateFakeID(Path());
WARN_LOG(LOADER, "No DiscID found - generating a fake one: '%s' (from %s)", fakeID.c_str(), PSP_CoreParameter().fileToStart.c_str());
ValueData data;
data.type = VT_UTF8;
Expand Down Expand Up @@ -320,15 +320,15 @@ void ParamSFOData::ValueData::SetData(const u8* data, int size) {
u_size = size;
}

std::string ParamSFOData::GenerateFakeID(const std::string &filename) const {
std::string ParamSFOData::GenerateFakeID(const Path &filename) const {
// Generates fake gameID for homebrew based on it's folder name.
// Should probably not be a part of ParamSFO, but it'll be called in same places.
std::string file = PSP_CoreParameter().fileToStart.ToString();
// FileToStart here is actually a directory name, not a file, so taking GetFilename on it gets what we want.
Path path = PSP_CoreParameter().fileToStart;
if (!filename.empty())
file = filename;
path = filename;

std::size_t lslash = file.find_last_of("/");
file = file.substr(lslash + 1);
std::string file = path.GetFilename();

int sumOfAllLetters = 0;
for (char &c : file) {
Expand Down
4 changes: 3 additions & 1 deletion Core/ELF/ParamSFO.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "Common/CommonTypes.h"
#include "Common/Log.h"

class Path;

class ParamSFOData
{
public:
Expand All @@ -36,7 +38,7 @@ class ParamSFOData
const u8 *GetValueData(const std::string &key, unsigned int *size) const;

std::vector<std::string> GetKeys() const;
std::string GenerateFakeID(const std::string &filename = "") const;
std::string GenerateFakeID(const Path &filename) const;

std::string GetDiscID();

Expand Down
2 changes: 1 addition & 1 deletion Core/PSPLoaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) {
homebrewTitle = homebrewName;
std::string discID = g_paramSFO.GetDiscID();
std::string discVersion = g_paramSFO.GetValueString("DISC_VERSION");
std::string madeUpID = g_paramSFO.GenerateFakeID();
std::string madeUpID = g_paramSFO.GenerateFakeID(Path());

std::string title = StringFromFormat("%s : %s", discID.c_str(), homebrewTitle.c_str());
INFO_LOG(LOADER, "%s", title.c_str());
Expand Down
2 changes: 1 addition & 1 deletion Core/SaveState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ namespace SaveState
std::string discId = g_paramSFO.GetValueString("DISC_ID");
std::string discVer = g_paramSFO.GetValueString("DISC_VERSION");
if (discId.empty()) {
discId = g_paramSFO.GenerateFakeID();
discId = g_paramSFO.GenerateFakeID(Path());
discVer = "1.00";
}
return StringFromFormat("%s_%s", discId.c_str(), discVer.c_str());
Expand Down
3 changes: 3 additions & 0 deletions GPU/Vulkan/TextureCacheVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
}

if (plan.saveTexture) {
INFO_LOG(G3D, "About to save texture");
actualFmt = VULKAN_8888_FORMAT;
}

Expand Down Expand Up @@ -647,6 +648,8 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
}
// Format might be wrong in lowMemoryMode_, so don't save.
if (plan.saveTexture && !lowMemoryMode_) {
INFO_LOG(G3D, "Calling NotifyTextureDecoded %08x", entry->addr);

// When hardware texture scaling is enabled, this saves the original.
int w = dataScaled ? mipWidth : mipUnscaledWidth;
int h = dataScaled ? mipHeight : mipUnscaledHeight;
Expand Down
2 changes: 1 addition & 1 deletion UI/CwCheatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool CwCheatScreen::TryLoadCheatInfo() {
}
if ((info->id.empty() || !info->disc_total)
&& gamePath_.FilePathContainsNoCase("PSP/GAME/")) {
gameID = g_paramSFO.GenerateFakeID(gamePath_.ToString());
gameID = g_paramSFO.GenerateFakeID(gamePath_);
}

if (!engine_ || gameID != gameID_) {
Expand Down
4 changes: 2 additions & 2 deletions UI/GameInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class GameInfoWorkItem : public Task {
if ((info_->id.empty() || !info_->disc_total)
&& gamePath_.FilePathContainsNoCase("PSP/GAME/")
&& info_->fileType == IdentifiedFileType::PSP_PBP_DIRECTORY) {
info_->id = g_paramSFO.GenerateFakeID(gamePath_.ToString());
info_->id = g_paramSFO.GenerateFakeID(gamePath_);
info_->id_version = info_->id + "_1.00";
info_->region = GAMEREGION_MAX + 1; // Homebrew
}
Expand Down Expand Up @@ -529,7 +529,7 @@ class GameInfoWorkItem : public Task {
// An elf on its own has no usable information, no icons, no nothing.
{
std::lock_guard<std::mutex> lock(info_->lock);
info_->id = g_paramSFO.GenerateFakeID(gamePath_.ToString());
info_->id = g_paramSFO.GenerateFakeID(gamePath_);
info_->id_version = info_->id + "_1.00";
info_->region = GAMEREGION_MAX + 1; // Homebrew

Expand Down
2 changes: 1 addition & 1 deletion UI/GameScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ UI::EventReturn GameScreen::OnGameSettings(UI::EventParams &e) {
if (info && info->paramSFOLoaded) {
std::string discID = info->paramSFO.GetValueString("DISC_ID");
if ((discID.empty() || !info->disc_total) && gamePath_.FilePathContainsNoCase("PSP/GAME/"))
discID = g_paramSFO.GenerateFakeID(gamePath_.ToString());
discID = g_paramSFO.GenerateFakeID(gamePath_);
screenManager()->push(new GameSettingsScreen(gamePath_, discID, true));
}
return UI::EVENT_DONE;
Expand Down

0 comments on commit 2e16fd3

Please sign in to comment.