rust3ds / ctru-rs

Rust wrapper for libctru
https://rust3ds.github.io/ctru-rs/
Other
117 stars 17 forks source link

Add Smdh struct #96

Closed Maccraft123 closed 9 months ago

Maccraft123 commented 1 year ago

This MR adds Smdh struct to read smdh data from ExeFS of CXI files and some related data, like flags and region lockout data. I wasn't really sure where to put it, so it went into src/smdh.rs and reading it went to src/services/am.rs as it's closely related to titles. I'm not sure what can I do to make the actual-reading of data in Title::get_smdh look nicer. I had an idea to make a somewhat-generic code for reading/writing from/to weird ArchiveIds with custom binary paths but I'm not sure how to implement it. The other part that looks sorta ugly-ish is verifying that smdh's magic data is 'SMDH', as I can't directly access magic field of Smdh from am.rs and it doesn't really make sense to add a public getter for it, so I added a public-to-crate getter for it.

I used https://www.3dbrew.org/wiki/SMDH and https://github.com/J-D-K/JKSM as references.

Maccraft123 commented 1 year ago

I haven't checked the code in depth (I have exams next week, so I don't think I will be able to), but you should remove most #[derive(Copy)]. I don't think that copying of big structs (Smdh, Title, etc) is a good idea, specially on a system like the 3DS

Sure, will do. Sorta got used to doing it whenever I can as I don't really care that much about performance until it becomes an issue. Will do my best to remember to not do that in future.

Maccraft123 commented 1 year ago

Tbh it might be a good idea to move Smdh, and other data formats(NCCH, CIA etc), into their own crate, so that it could be used with tools that don't run on 3ds

Meziu commented 1 year ago

Tbh it might be a good idea to move Smdh, and other data formats(NCCH, CIA etc), into their own crate, so that it could be used with tools that don't run on 3ds

That is a very interesting point, especially since our tools (mainly cargo-3ds) would benefit immensely from having custom file format support rather than depending on installed binaries.

Maccraft123 commented 1 year ago

That is a very interesting point, especially since our tools (mainly cargo-3ds) would benefit immensely from having custom file format support rather than depending on installed binaries.

If you want, I can try making a proof of concept for Rust smdhtool alternative and a Rust library to read/write SMDH data

Maccraft123 commented 1 year ago

Yeah, I can see it work, https://github.com/Maccraft123/ctr-formats https://github.com/Maccraft123/ctru-rs/commit/02d32b1cf81ce8a962e3c5ce2f89d80027827be9