RatchetModding / Replanetizer

Replanetizer is a Level Editor for the Ratchet & Clank HD collection.
GNU General Public License v3.0
65 stars 14 forks source link

PSARC Unpacker #66

Open MilchRatchet opened 2 years ago

MilchRatchet commented 2 years ago

Currently it is non trivial to unpack the psarcs as the download sources of many tools are offline and the rest are either only available through source code or through our discord.

I have no clue how feasible it is to encorporate this here but we should at least consider it.

maikelwever commented 2 years ago

Reading from psarcs is not that difficult, enough C# snippets can be found to achieve that. Adding a tool that can extract psarcs in their current folder would be pretty doable. But it's also quite inefficient on storage if you only wanted to read some data.

Reading and writing in-place is the problem mostly, as rewriting the entire arc is slow, and just appending new data will bloat up the file size.

I've been thinking about this in the past, and a virtual filesystem would fix this problem. Specifically, a virtual filesystem that is composed of layers of other filesystems. This way, writes will go to the top level, and reads will pick the first occurrence of a file, from top to bottom.

At the bottom we have the game data folder, which also contains the big psarc file. We mount the psarc file on top of the data folder, since they share the same folder structure anyway. On top we mount a folder that the user specifies, let's call this workspace folder. We send write calls directly to the workspace folder, bypassing the VFS. Some smartness to check if the file we're writing is already identical in the game data folder or psarc would be required, otherwise this would just be a very inefficient psarc unpacker.

Hopefully, you could then just copy your workspace into the game folder on your PS3, and it would load the changed files automatically. I'm not sure if that works or if you'd still need a dummy psarc in that case.

I've been experimenting with such a setup a while ago, using https://github.com/xoofx/zio , which provides a bunch of virtual filesystem tooling for C#. I've also copied some code from another C# psarc unpacker, and put it into a Zio interface: https://github.com/maikelwever/Zio_PSArcFIleSystem , but that's not polished in the slightest at this moment.

The most boring part is to rewrite every single file reading call currently in LibReplanetizer to the new VFS. Most standard library utils (for example walking or globbing through directories) are not compatible with VFS, and would need to be replaced as well.

It would be logical to combine something like the above with a way to open up an entire ps3 disc in Replanetizer, and showing all detected games and levels in the UI.

MilchRatchet commented 2 years ago

Hopefully, you could then just copy your workspace into the game folder on your PS3, and it would load the changed files automatically. I'm not sure if that works or if you'd still need a dummy psarc in that case.

I think the files in the psarc take precedent over the other files, meaning if we only wanted to store the files that changed we would need to delete those files from the psarc. The easiest would probably then be to simply have an empty dummy psarc and simply store all files even if they were not changed, this way we could simply ignore having to modify psarcs ever. Not sure whether the VFS is still that useful then.

stiantoften commented 2 years ago

It would be useful to have an "export to psarc" option in case you want to pack up the levels for easier installs on other systems. This could be implemented as a seperate thing though, with a disclaimer that the export will take a while since it has to rebuild it all.

MilchRatchet commented 7 months ago

I have made a C++ library for interfacing with playstation archives. It is still in an early state but once I have implemented a C API, we could think about integrating this into Replanetizer.