u64 Memory::read64(u32 addr) { return re64(*(u64*)((u64)m_base + addr)); }
void Memory::write64(u32 addr, u64 value) { *(u64*)((u64)m_base + addr) = re64(value); }
__forceinline void Write64(const fs::file& f, const u64 data) { Write64LE(f, re64(data)); }
int sdata_unpack(const std::string& packed_file, const std::string& unpacked_file) { std::shared_ptr<vfsFileBase> packed_stream(Emu.GetVFS().OpenFile(packed_file, vfsRead)); std::shared_ptr<vfsFileBase> unpacked_stream(Emu.GetVFS().OpenFile(unpacked_file, vfsWrite)); if(!packed_stream || !packed_stream->IsOpened()) { sys_fs.Error("'%s' not found! flags: 0x%08x", packed_file.c_str(), vfsRead); return CELL_ENOENT; } if(!unpacked_stream || !unpacked_stream->IsOpened()) { sys_fs.Error("'%s' couldn't be created! flags: 0x%08x", unpacked_file.c_str(), vfsWrite); return CELL_ENOENT; } char buffer [10200]; packed_stream->Read(buffer, 256); u32 format = re32(*(u32*)&buffer[0]); if (format != 0x4E504400) // "NPD\x00" { sys_fs.Error("Illegal format. Expected 0x4E504400, but got 0x%08x", format); return CELL_EFSSPECIFIC; } u32 version = re32(*(u32*)&buffer[0x04]); u32 flags = re32(*(u32*)&buffer[0x80]); u32 blockSize = re32(*(u32*)&buffer[0x84]); u64 filesizeOutput = re64(*(u64*)&buffer[0x88]); u64 filesizeInput = packed_stream->GetSize(); u32 blockCount = (filesizeOutput + blockSize-1) / blockSize; // SDATA file is compressed if (flags & 0x1) { sys_fs.Warning("cellFsSdataOpen: Compressed SDATA files are not supported yet."); return CELL_EFSSPECIFIC; } // SDATA file is NOT compressed else { u32 t1 = (flags & 0x20) ? 0x20 : 0x10; u32 startOffset = (blockCount * t1) + 0x100; u64 filesizeTmp = (filesizeOutput+0xF)&0xFFFFFFF0 + startOffset; if (!sdata_check(version, flags, filesizeInput, filesizeTmp)) { sys_fs.Error("cellFsSdataOpen: Wrong header information."); return CELL_EFSSPECIFIC; } if (flags & 0x20) packed_stream->Seek(0x100); else packed_stream->Seek(startOffset); for (u32 i = 0; i < blockCount; i++) { if (flags & 0x20) packed_stream->Seek(packed_stream->Tell() + t1); if (!(blockCount-i-1)) blockSize = filesizeOutput-i*blockSize; packed_stream->Read(buffer+256, blockSize); unpacked_stream->Write(buffer+256, blockSize); } } return CELL_OK; }
__forceinline void Write64(vfsStream& f, const u64 data) { Write64LE(f, re64(data)); }