Merge pull request #19520 from hrydgard/more-fixes

More assorted fixes
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2024-10-10 23:35:44 +02:00
commit f930f52b37
10 files changed
+177 -140

No files matched your search

+6 -5
View File
@@ -102,16 +102,17 @@ int Buffer::OffsetToAfterNextCRLF() {
}
void Buffer::Printf(const char *fmt, ...) {
char buffer[2048];
char buffer[4096];
va_list vl;
va_start(vl, fmt);
size_t retval = vsnprintf(buffer, sizeof(buffer), fmt, vl);
if ((int)retval >= (int)sizeof(buffer)) {
int retval = vsnprintf(buffer, sizeof(buffer), fmt, vl);
if (retval >= (int)sizeof(buffer)) {
// Output was truncated. TODO: Do something.
ERROR_LOG(Log::IO, "Buffer::Printf truncated output");
}
if ((int)retval < 0) {
ERROR_LOG(Log::IO, "Buffer::Printf failed");
if (retval < 0) {
ERROR_LOG(Log::IO, "Buffer::Printf failed, bad args?");
return;
}
va_end(vl);
char *ptr = Append(retval);
+1 -1
View File
@@ -74,8 +74,8 @@ VulkanPushPool::Block VulkanPushPool::CreateBlock(size_t size) {
_assert_(result == VK_SUCCESS);
result = vmaMapMemory(vulkan_->Allocator(), block.allocation, (void **)(&block.writePtr));
_assert_msg_(result == VK_SUCCESS, "VulkanPushPool: Failed to map memory (result = %s)", VulkanResultToString(result));
_assert_msg_(result == VK_SUCCESS, "VulkanPushPool: Failed to map memory (result = %s, size = %d)", VulkanResultToString(result), (int)size);
_assert_msg_(block.writePtr != nullptr, "VulkanPushPool: Failed to map memory on block of size %d", (int)block.size);
return block;
}
+64 -64
View File
@@ -37,8 +37,6 @@ extern "C"
#include "ext/libkirk/kirk_engine.h"
};
std::mutex NPDRMDemoBlockDevice::mutex_;
BlockDevice *constructBlockDevice(FileLoader *fileLoader) {
if (!fileLoader->Exists()) {
return nullptr;
@@ -389,8 +387,7 @@ NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader)
MAC_KEY mkey;
CIPHER_KEY ckey;
u8 np_header[256];
u32 tableOffset, tableSize;
u32 lbaStart, lbaEnd;
u32 tableOffset_, tableSize_;
fileLoader_->ReadAt(0x24, 1, 4, &psarOffset);
size_t readSize = fileLoader_->ReadAt(psarOffset, 1, 256, &np_header);
@@ -411,29 +408,38 @@ NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader)
sceDrmBBCipherUpdate(&ckey, np_header+0x40, 0x60);
sceDrmBBCipherFinal(&ckey);
lbaStart = *(u32*)(np_header+0x54); // LBA start
lbaEnd = *(u32*)(np_header+0x64); // LBA end
lbaSize = (lbaEnd-lbaStart+1); // LBA size of ISO
blockLBAs = *(u32*)(np_header+0x0c); // block size in LBA
blockSize = blockLBAs*2048;
numBlocks = (lbaSize+blockLBAs-1)/blockLBAs; // total blocks;
u32 lbaStart = *(u32*)(np_header+0x54); // LBA start
u32 lbaEnd = *(u32*)(np_header+0x64); // LBA end
lbaSize_ = (lbaEnd-lbaStart+1); // LBA size of ISO
blockLBAs_ = *(u32*)(np_header+0x0c); // block size in LBA
blockBuf = new u8[blockSize];
tempBuf = new u8[blockSize];
// Protect against a badly decrypted header, and send information through the assert about what's being played (implicitly).
_assert_msg_(blockLBAs_ <= 4096, "Bad blockLBAs in header: %08x (%s)", blockLBAs_, fileLoader->GetPath().ToVisualString().c_str());
tableOffset = *(u32*)(np_header+0x6c); // table offset
// When we remove the above assert, let's just try to survive.
if (blockLBAs_ > 4096) {
return;
}
tableSize = numBlocks*32;
table = new table_info[numBlocks];
blockSize_ = blockLBAs_ * 2048;
numBlocks_ = (lbaSize_ + blockLBAs_-1) / blockLBAs_; // total blocks;
readSize = fileLoader_->ReadAt(psarOffset + tableOffset, 1, tableSize, table);
if(readSize!=tableSize){
blockBuf_ = new u8[blockSize_];
tempBuf_ = new u8[blockSize_];
tableOffset_ = *(u32*)(np_header+0x6c); // table offset
tableSize_ = numBlocks_ * 32;
table_ = new table_info[numBlocks_];
readSize = fileLoader_->ReadAt(psarOffset + tableOffset_, 1, tableSize_, table_);
if (readSize!=tableSize_){
ERROR_LOG(Log::Loader, "Invalid NPUMDIMG table!");
}
u32 *p = (u32*)table;
u32 *p = (u32*)table_;
u32 i, k0, k1, k2, k3;
for(i=0; i<numBlocks; i++){
for (i=0; i<numBlocks_; i++){
k0 = p[0]^p[1];
k1 = p[1]^p[2];
k2 = p[0]^p[3];
@@ -445,86 +451,83 @@ NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader)
p += 8;
}
currentBlock = -1;
currentBlock_ = -1;
}
NPDRMDemoBlockDevice::~NPDRMDemoBlockDevice()
{
NPDRMDemoBlockDevice::~NPDRMDemoBlockDevice() {
std::lock_guard<std::mutex> guard(mutex_);
delete [] table;
delete [] tempBuf;
delete [] blockBuf;
delete [] table_;
delete [] tempBuf_;
delete [] blockBuf_;
}
int lzrc_decompress(void *out, int out_len, void *in, int in_len);
bool NPDRMDemoBlockDevice::ReadBlock(int blockNumber, u8 *outPtr, bool uncached)
{
bool NPDRMDemoBlockDevice::ReadBlock(int blockNumber, u8 *outPtr, bool uncached) {
FileLoader::Flags flags = uncached ? FileLoader::Flags::HINT_UNCACHED : FileLoader::Flags::NONE;
std::lock_guard<std::mutex> guard(mutex_);
CIPHER_KEY ckey;
int block, lba, lzsize;
size_t readSize;
u8 *readBuf;
lba = blockNumber-currentBlock;
if(lba>=0 && lba<blockLBAs){
memcpy(outPtr, blockBuf+lba*2048, 2048);
if (blockSize_ == 0) {
// Wasn't opened successfully.
return false;
}
int lba = blockNumber - currentBlock_;
if (lba >= 0 && lba < blockLBAs_){
memcpy(outPtr, blockBuf_ + lba*2048, 2048);
return true;
}
block = blockNumber/blockLBAs;
lba = blockNumber%blockLBAs;
currentBlock = block*blockLBAs;
int block = blockNumber / blockLBAs_;
lba = blockNumber % blockLBAs_;
currentBlock_ = block * blockLBAs_;
if(table[block].unk_1c!=0){
if((u32)block==(numBlocks-1))
if (table_[block].unk_1c != 0) {
if((u32)block == (numBlocks_ - 1))
return true; // demos make by fake_np
else
return false;
}
if(table[block].size<blockSize)
readBuf = tempBuf;
u8 *readBuf;
if (table_[block].size < blockSize_)
readBuf = tempBuf_;
else
readBuf = blockBuf;
readBuf = blockBuf_;
readSize = fileLoader_->ReadAt(psarOffset+table[block].offset, 1, table[block].size, readBuf, flags);
if(readSize != (size_t)table[block].size){
if((u32)block==(numBlocks-1))
size_t readSize = fileLoader_->ReadAt(psarOffset+table_[block].offset, 1, table_[block].size, readBuf, flags);
if (readSize != (size_t)table_[block].size){
if((u32)block==(numBlocks_-1))
return true;
else
return false;
}
if((table[block].flag&1)==0){
if ((table_[block].flag & 1) == 0) {
// skip mac check
}
if((table[block].flag&4)==0){
sceDrmBBCipherInit(&ckey, 1, 2, hkey, vkey, table[block].offset>>4);
sceDrmBBCipherUpdate(&ckey, readBuf, table[block].size);
if ((table_[block].flag & 4) == 0) {
CIPHER_KEY ckey;
sceDrmBBCipherInit(&ckey, 1, 2, hkey, vkey, table_[block].offset>>4);
sceDrmBBCipherUpdate(&ckey, readBuf, table_[block].size);
sceDrmBBCipherFinal(&ckey);
}
if(table[block].size<blockSize){
lzsize = lzrc_decompress(blockBuf, 0x00100000, readBuf, table[block].size);
if(lzsize!=blockSize){
if (table_[block].size < blockSize_) {
int lzsize = lzrc_decompress(blockBuf_, 0x00100000, readBuf, table_[block].size);
if(lzsize!=blockSize_){
ERROR_LOG(Log::Loader, "LZRC decompress error! lzsize=%d\n", lzsize);
NotifyReadError();
return false;
}
}
memcpy(outPtr, blockBuf+lba*2048, 2048);
memcpy(outPtr, blockBuf_+lba*2048, 2048);
return true;
}
/*
* CHD file
*/
static const UINT8 nullsha1[CHD_SHA1_BYTES] = { 0 };
// static const UINT8 nullsha1[CHD_SHA1_BYTES] = { 0 };
struct CHDImpl {
chd_file *chd = nullptr;
@@ -537,8 +540,7 @@ struct ExtendedCoreFile {
};
CHDFileBlockDevice::CHDFileBlockDevice(FileLoader *fileLoader)
: BlockDevice(fileLoader), impl_(new CHDImpl())
{
: BlockDevice(fileLoader), impl_(new CHDImpl()) {
Path paths[8];
paths[0] = fileLoader->GetPath();
int depth = 0;
@@ -650,16 +652,14 @@ CHDFileBlockDevice::CHDFileBlockDevice(FileLoader *fileLoader)
numBlocks = impl_->header->unitcount;
}
CHDFileBlockDevice::~CHDFileBlockDevice()
{
CHDFileBlockDevice::~CHDFileBlockDevice() {
if (impl_->chd) {
chd_close(impl_->chd);
delete[] readBuffer;
}
}
bool CHDFileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr, bool uncached)
{
bool CHDFileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr, bool uncached) {
if (!impl_->chd) {
ERROR_LOG(Log::Loader, "ReadBlock: CHD not open. %s", fileLoader_->GetPath().c_str());
return false;
+15 -13
View File
@@ -113,25 +113,27 @@ public:
~NPDRMDemoBlockDevice();
bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override;
u32 GetNumBlocks() const override {return (u32)lbaSize;}
u32 GetNumBlocks() const override {return (u32)lbaSize_;}
bool IsDisc() const override { return false; }
private:
static std::mutex mutex_;
u32 lbaSize;
// TODO: Doubt this mutex is actually needed.
std::mutex mutex_;
u32 psarOffset;
int blockSize;
int blockLBAs;
u32 numBlocks;
u32 lbaSize_ = 0;
u8 vkey[16];
u8 hkey[16];
struct table_info *table;
u32 psarOffset = 0;
int blockSize_ = 0;
int blockLBAs_ = 0;
u32 numBlocks_ = 0;
int currentBlock;
u8 *blockBuf;
u8 *tempBuf;
u8 vkey[16]{};
u8 hkey[16]{};
struct table_info *table_ = nullptr;
int currentBlock_ = 0;
u8 *blockBuf_ = nullptr;
u8 *tempBuf_ = nullptr;
};
struct CHDImpl;
+5
View File
@@ -637,6 +637,11 @@ bool ZipExtractFileToMemory(struct zip *z, int fileIndex, std::string *data) {
data->resize(readSize);
zip_file *zf = zip_fopen_index(z, fileIndex, 0);
if (!zf) {
ERROR_LOG(Log::HLE, "Failed to zip_fopen_index file %d from zip", fileIndex);
return false;
}
zip_int64_t retval = zip_fread(zf, data->data(), readSize);
zip_fclose(zf);
+21 -11
View File
@@ -664,18 +664,21 @@ static bool WriteTextureToPNG(png_imagep image, const Path &filename, int conver
// can be pretty slow.
class SaveTextureTask : public Task {
public:
std::vector<u8> rgbaData;
// malloc'd
u8 *rgbaData = nullptr;
int w = 0;
int h = 0;
int pitch = 0; // bytes
Path filename;
Path saveFilename;
u32 replacedInfoHash = 0;
SaveTextureTask(std::vector<u8> &&_rgbaData) : rgbaData(std::move(_rgbaData)) {}
SaveTextureTask(u8 *_rgbaData) : rgbaData(_rgbaData) {}
~SaveTextureTask() {
free(rgbaData);
}
// This must be set to I/O blocking because of Android storage (so we attach the thread to JNI), while being CPU heavy too.
TaskType Type() const override { return TaskType::IO_BLOCKING; }
@@ -711,7 +714,7 @@ public:
png.format = PNG_FORMAT_RGBA;
png.width = w;
png.height = h;
bool success = WriteTextureToPNG(&png, saveFilename, 0, rgbaData.data(), pitch, nullptr);
bool success = WriteTextureToPNG(&png, saveFilename, 0, rgbaData, w * 4, nullptr);
png_image_free(&png);
if (png.warning_or_error >= 2) {
ERROR_LOG(Log::G3D, "Saving texture to PNG produced errors.");
@@ -735,9 +738,9 @@ bool TextureReplacer::WillSave(const ReplacedTextureDecodeInfo &replacedInfo) co
return true;
}
void TextureReplacer::NotifyTextureDecoded(ReplacedTexture *texture, const ReplacedTextureDecodeInfo &replacedInfo, const void *data, int pitch, int level, int origW, int origH, int scaledW, int scaledH) {
void TextureReplacer::NotifyTextureDecoded(ReplacedTexture *texture, const ReplacedTextureDecodeInfo &replacedInfo, const void *data, int srcPitch, int level, int origW, int origH, int scaledW, int scaledH) {
_assert_msg_(saveEnabled_, "Texture saving not enabled");
_assert_(pitch >= 0);
_assert_(srcPitch >= 0);
if (!WillSave(replacedInfo)) {
// Ignore.
@@ -787,6 +790,10 @@ void TextureReplacer::NotifyTextureDecoded(ReplacedTexture *texture, const Repla
int w = scaledW;
int h = scaledH;
if (w == 0 || h == 0) {
return;
}
// Only save the hashed portion of the PNG.
int lookupW;
int lookupH;
@@ -795,15 +802,19 @@ void TextureReplacer::NotifyTextureDecoded(ReplacedTexture *texture, const Repla
h = lookupH * (scaledH / origH);
}
std::vector<u8> saveBuf;
size_t saveBufSize = w * h * 4;
u8 *saveBuf = (u8 *)malloc(saveBufSize);
if (!saveBuf) {
ERROR_LOG(Log::G3D, "Failed to allocated %d bytes of memory for saving a texture", (int)saveBufSize);
return;
}
// Copy data to a buffer so we can send it to the thread. Might as well compact-away the pitch
// while we're at it.
saveBuf.resize(w * h * 4);
for (int y = 0; y < h; y++) {
memcpy((u8 *)saveBuf.data() + y * w * 4, (const u8 *)data + y * pitch, w * 4);
memcpy(saveBuf + y * w * 4, (const u8 *)data + y * srcPitch, w * 4);
}
pitch = w * 4;
SaveTextureTask *task = new SaveTextureTask(std::move(saveBuf));
@@ -812,7 +823,6 @@ void TextureReplacer::NotifyTextureDecoded(ReplacedTexture *texture, const Repla
task->w = w;
task->h = h;
task->pitch = pitch;
task->replacedInfoHash = replacedInfo.hash;
g_threadManager.EnqueueTask(task); // We don't care about waiting for the task. It'll be fine.
+1 -1
View File
@@ -496,7 +496,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
}
if (plan.saveTexture) {
INFO_LOG(Log::G3D, "About to save texture");
INFO_LOG(Log::G3D, "About to save texture (%dx%d)", plan.createW, plan.createH);
actualFmt = VULKAN_8888_FORMAT;
}
+42 -36
View File
@@ -80,8 +80,10 @@ void GameScreen::update() {
if (Reporting::HasCRC(gamePath_)) {
uint32_t crcvalue = Reporting::RetrieveCRC(gamePath_);
CRC32string = int2hexstr(crcvalue);
tvCRC_->SetVisibility(UI::V_VISIBLE);
tvCRC_->SetText(CRC32string);
if (tvCRC_) {
tvCRC_->SetVisibility(UI::V_VISIBLE);
tvCRC_->SetText(CRC32string);
}
if (tvCRCCopy_) {
tvCRCCopy_->SetVisibility(UI::V_VISIBLE);
}
@@ -114,6 +116,21 @@ void GameScreen::CreateViews() {
ViewGroup *leftColumn = new AnchorLayout(new LinearLayoutParams(1.0f));
root_->Add(leftColumn);
bool fileTypeSupportCRC = false;
if (info) {
switch (info->fileType) {
case IdentifiedFileType::PSP_PBP:
case IdentifiedFileType::PSP_PBP_DIRECTORY:
case IdentifiedFileType::PSP_ISO_NP:
case IdentifiedFileType::PSP_ISO:
fileTypeSupportCRC = true;
break;
default:
break;
}
}
leftColumn->Add(new Choice(di->T("Back"), "", false, new AnchorLayoutParams(150, WRAP_CONTENT, 10, NONE, NONE, 10)))->OnClick.Handle(this, &GameScreen::OnSwitchBack);
if (info->Ready(GameInfoFlags::PARAM_SFO)) {
ViewGroup *badgeHolder = new LinearLayout(ORIENT_HORIZONTAL, new AnchorLayoutParams(10, 10, 110, NONE));
@@ -151,25 +168,29 @@ void GameScreen::CreateViews() {
tvPlayTime_->SetVisibility(V_GONE);
LinearLayout *crcHoriz = infoLayout->Add(new LinearLayout(ORIENT_HORIZONTAL));
tvCRC_ = crcHoriz->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(0.0, G_VCENTER)));
tvCRC_->SetShadow(true);
Visibility crcVisibility = Reporting::HasCRC(gamePath_) ? V_VISIBLE : V_GONE;
tvCRC_->SetVisibility(crcVisibility);
if (System_GetPropertyBool(SYSPROP_HAS_TEXT_CLIPBOARD)) {
tvCRCCopy_ = crcHoriz->Add(new Button(di->T("Copy to clipboard"), new LinearLayoutParams(0.0, G_VCENTER)));
tvCRCCopy_->OnClick.Add([this](UI::EventParams &) {
u32 crc = Reporting::RetrieveCRC(gamePath_);
char buffer[16];
snprintf(buffer, sizeof(buffer), "%08X", crc);
System_CopyStringToClipboard(buffer);
// Success indication. Not worth a translatable string.
g_OSD.Show(OSDType::MESSAGE_SUCCESS, buffer, 1.0f);
return UI::EVENT_DONE;
});
tvCRCCopy_->SetVisibility(crcVisibility);
tvCRCCopy_->SetScale(0.82f);
} else {
tvCRCCopy_ = nullptr;
if (fileTypeSupportCRC) {
// CRC button makes sense.
tvCRC_ = crcHoriz->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(0.0, G_VCENTER)));
tvCRC_->SetShadow(true);
Visibility crcVisibility = Reporting::HasCRC(gamePath_) ? V_VISIBLE : V_GONE;
tvCRC_->SetVisibility(crcVisibility);
if (System_GetPropertyBool(SYSPROP_HAS_TEXT_CLIPBOARD)) {
tvCRCCopy_ = crcHoriz->Add(new Button(di->T("Copy to clipboard"), new LinearLayoutParams(0.0, G_VCENTER)));
tvCRCCopy_->OnClick.Add([this](UI::EventParams &) {
u32 crc = Reporting::RetrieveCRC(gamePath_);
char buffer[16];
snprintf(buffer, sizeof(buffer), "%08X", crc);
System_CopyStringToClipboard(buffer);
// Success indication. Not worth a translatable string.
g_OSD.Show(OSDType::MESSAGE_SUCCESS, buffer, 1.0f);
return UI::EVENT_DONE;
});
tvCRCCopy_->SetVisibility(crcVisibility);
tvCRCCopy_->SetScale(0.82f);
} else {
tvCRCCopy_ = nullptr;
}
}
tvVerified_ = infoLayout->Add(new NoticeView(NoticeLevel::INFO, ga->T("Click \"Calculate CRC\" to verify ISO"), "", new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
@@ -269,21 +290,6 @@ void GameScreen::CreateViews() {
btnSetBackground_->OnClick.Handle(this, &GameScreen::OnSetBackground);
btnSetBackground_->SetVisibility(V_GONE);
bool fileTypeSupportCRC = false;
if (info) {
switch (info->fileType) {
case IdentifiedFileType::PSP_PBP:
case IdentifiedFileType::PSP_PBP_DIRECTORY:
case IdentifiedFileType::PSP_ISO_NP:
case IdentifiedFileType::PSP_ISO:
fileTypeSupportCRC = true;
break;
default:
break;
}
}
isHomebrew_ = info && info->region > GAMEREGION_MAX;
if (fileTypeSupportCRC && !isHomebrew_ && !Reporting::HasCRC(gamePath_) ) {
btnCalcCRC_ = rightColumnItems->Add(new ChoiceWithValueDisplay(&CRC32string, ga->T("Calculate CRC"), I18NCat::NONE));
+12 -3
View File
@@ -10,6 +10,7 @@
#include "Common/Data/Encoding/Utf8.h"
#include "Common/StringUtils.h"
#include "Common/File/FileUtil.h"
#include "Common/Log.h"
bool KeyDownAsync(int vkey) {
#if PPSSPP_PLATFORM(UWP)
@@ -101,14 +102,22 @@ namespace W32Util
// SHParseDisplayName can't handle relative paths, so normalize first.
std::string resolved = ReplaceAll(File::ResolvePath(path), "/", "\\");
SFGAOF flags{};
// Shell also can't handle \\?\UNC\ paths.
// TODO: Move this to ResolvePath?
if (startsWith(resolved, "\\\\?\\UNC\\")) {
resolved = "\\" + resolved.substr(7);
}
PIDLIST_ABSOLUTE pidl = nullptr;
HRESULT hr = SHParseDisplayName(ConvertUTF8ToWString(resolved).c_str(), nullptr, &pidl, 0, &flags);
std::wstring wresolved = ConvertUTF8ToWString(resolved);
HRESULT hr = SHParseDisplayName(wresolved.c_str(), nullptr, &pidl, 0, nullptr);
if (pidl) {
if (SUCCEEDED(hr))
SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0);
CoTaskMemFree(pidl);
ILFree(pidl);
} else {
ERROR_LOG(Log::System, "SHParseDisplayName failed: %s", resolved.c_str());
}
}
@@ -22,12 +22,16 @@ public class TextRenderer {
}
public static void init(Context ctx) {
robotoCondensed = Typeface.createFromAsset(ctx.getAssets(), "Roboto-Condensed.ttf");
if (robotoCondensed != null) {
Log.i(TAG, "Successfully loaded Roboto Condensed");
textPaint.setTypeface(robotoCondensed);
} else {
Log.e(TAG, "Failed to load Roboto Condensed");
try {
robotoCondensed = Typeface.createFromAsset(ctx.getAssets(), "Roboto-Condensed.ttf");
if (robotoCondensed != null) {
Log.i(TAG, "Successfully loaded Roboto Condensed");
textPaint.setTypeface(robotoCondensed);
} else {
Log.e(TAG, "Failed to load Roboto Condensed");
}
} catch (Exception e) {
Log.e(TAG, "Exception when loading typeface. shouldn't happen but is reported. We just fall back." + e);
}
highContrastFontsEnabled = Settings.Secure.getInt(ctx.getContentResolver(), "high_text_contrast_enabled", 0) == 1;
}