karas84 / ProjectZeroUndub

Undub project for Tecmo's Project Zero - the EU version (the first one) for the PS2
MIT License
7 stars 0 forks source link

Merging/Adding To Main ZeroUndub Repo #2

Open wagrenier opened 1 year ago

wagrenier commented 1 year ago

Hi there!

I just noticed your repo and how it supports all languages and adds patches for things like 16:9. I was wondering if you would be interested in merging your work into the main repo? We could work together on adding your features into C#. My code is fairly simple and should be easy to add new stuff.

Side note, the game already had a python version (experimental) in a different repo where I did my research. Also, if you are interested I am currently working on a reimplementation of Zero 2 called Mikompilation. Our discord is available in the README, feel free to join us!

In your what's next you talk about other file types that the game has, good news I have already reversed most of them :)

https://github.com/wagrenier/GameReversing https://github.com/wagrenier/Mikompilation

karas84 commented 1 year ago

Hi @wagrenier, first of all, thanks for reaching out, and also thanks (again) for you great work. It's been an inspiration for me.

As for your request, I would be more than happy to see my code merged into your repo. My only issue here is that I really don't have time to commit to it, unfortunately. My current work is keeping me very busy, in fact, I had to push back a lot of little progress I did for this repo and about the documentation. What I can do though, is to help you with understanding my code and how to integrate it in yours.

If I remember correctly, the way you and I do the patching is a little bit different. I think, but correct me if I'm wrong, that you rely on absolute offsets in the ISO to do the patching, while I fully parse the IMG_BD.BIN and all it's content to extract, patch and repack the data (which is also done in place between the two ISOs, without extracting anything). I also unpack, patch and repack the language files into the new IMG_BD.BIN.

And all these parsing and repacking is what the documentation is about. I'm almost done writing it but I could share it (or just push it upstream as it is right now) to give you a better idea of how the code works. I also discovered a lot of fun stuff about how the game was translated, as there are quite a few lines of text that have left unused from the Japanese release.

Like, the Japanese version used to have 5 more character tables for including all the Kanjis but since the PAL version only needs one, they removed the special characters used to address the other tables but left all other characters there. So when parsing those lines, they end up being garbled text, but looking at the Japanese version, one can see that everything else (the offsets to address the characters in the tables) is still there! On the contrary, the US version (if I remember correctly) retains all the japanese tables, and when unpacking the language files one can fully recover the unused Japanese text :).

Back OT, it is certainly possible to merge all of this into your code, but it's probably not going to be an easy feat. But again, I will be more than happy to help!

As a side note, I'm also almost done implementing a very rudimental GUI in tkinter (for compatibility with all platforms) to do the patching, as most users are probably not used to doing it with a CLI. I'm also working on a FUSE python driver to mount the ISO and expose the contents of the IMG_BD.BIN as standard files, also presenting the TIM images as JPEG/PNGs and the audio files as WAV files (doing all the conversions in the background).

Finally, I'll most certainly give the discord server a visit! And really really great work on the decompilation of PJZ2, that looks so cool!

wagrenier commented 1 year ago

I basically have ISO offsets for the beginning of the IMG_BD.BIN file, the elf, and the IMG_HD.BIN. After that I just replace the files that I need in the IMG_BD.BIN file and patch the size and offsets in the IMG_HD.BIN. When needed, I patch some instructions in the elf to make subtitles possible. I also made adding bigger files in the IMG_BD.BIN possible by some hacks without having to rebuild an entire ISO.

For audio files, FF1 uses its own compression algorithm. For image files, I have some C++ code that parses TIM2 files and can convert them into PNG. The reading of the TIM2 file was taken from FF2 which is how the official SDK loads TIM2.

For text files, all version of the games (including FF1/FF2/FF3) have hard coded memory limitations in the code making it impossible to have them beyond a certain size.

If you are on the discord, let me know by stating you came from this issue.

My initial patcher was going to work similarly to yours, but my lack of skills to package python apps lead me to C#. My futures goals for the undub would be to add direct support for Widescreen, fix graphical settings, and add support for other languages.

Final note, if you want on the discord server I have a channel for mods which includes a genuine widescreen patch which modifies the floats for x&y aspect ratio without affecting anything else. Because those are the right values, there are no other side effects like misaligned flashlights.

karas84 commented 1 year ago

What do you mean by "text files have hard coded memory limitations in the code making it impossible to have them beyond a certain size"? Are you talking about the file format, the number of entries in a single text file or the fact that the game code cannot address beyond a certain number of text entires in a file? I'm actually quite curious about this as I've written a small routine to unpack and repack language files but, from the viewpoint of the file format I don't see any particular limitations.

wagrenier commented 1 year ago

The game has hardcoded memory locations for static files, and as such if you exceed a certain size for oen of those files then they will get overwritten by the next file

karas84 commented 1 year ago

Thanks for the info! Do you know the exact dimension? Or is it different for different kinds of files (e.g., images are probably going to take up more space than text, so it could make sense to reserve more space for them)?

I've also finally decided to publish the tools I created to do the initial editing of the main files of the game for this repo. If you are interested, you can find them over https://github.com/karas84/ProjectZeroTools.

They are mainly focused on unpacking and repacking the main BIN data of the game and all OBJ text files. It's not limited to the subtitles but can handle all in-game texts.

In the same repo, I've also tried to document both file formats, and if possible, I plan to expand it to other formats.

Of course, it does not come close to the decompilation you are doing for Project Zero 2 but I figured it would be better to publish it than keeping it hidden in a folder forever.

LividBunny commented 1 year ago

Bless you both. 🙏