Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++ port #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add C++ port #3

wants to merge 1 commit into from

Conversation

dracc
Copy link

@dracc dracc commented Aug 15, 2023

Easily buildable

For Linux:
g++ main.cpp -llz4
For Windows:
x86_64-w64-mingw32-g++ main.cpp -llz4 -static

Easily buildable

For Linux:
g++ main.cpp -llz4
For Windows:
x86_64-w64-mingw32-g++ main.cpp -llz4 -static
try {
f.seekg(0x18310000, std::ios::beg);
} catch (std::exception const& e) {
std::cout << "File not big enough to be a Redump style image." << std::endl;
Copy link

@GXTX GXTX Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Why are we flushing on almost every cout, and some cerr's where we immediately exit, are we not trusting the OS?

const std::string CISO_MAGIC = "CISO";
const uint32_t CISO_HEADER_SIZE = 0x18;
const uint32_t CISO_BLOCK_SIZE = 0x800;
const uint32_t CISO_PLAIN_BLOCK = 0x80000000;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Above should probably be constexpr


void detect_iso_type(std::ifstream& f) {
try {
f.seekg(0x18310000, std::ios::beg);
Copy link

@GXTX GXTX Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Magic offsets all over

if (f.tellg() == 0x18310000) {
std::string buf(20, '\0');
f.read(&buf[0], 20);
if (buf == "MICROSOFT*XBOX*MEDIA") {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Used more than once should probably be a constexpr var


uint32_t get_block_size() { return block_size; };
uint32_t get_total_blocks() { return total_blocks; };
uint32_t get_align() { return align; };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Extra ;?


void write_block_index(std::ofstream& f, std::vector<uint32_t> const& block_index) {
for (uint32_t i: block_index) {
f.write((char*)&i, sizeof(i));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: C style casts throughout

std::cerr << "CompressionContext creation failed, exiting...";
exit(2);
}
std::ofstream fout_1(infile + ".1.cso", std::ios::binary);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Output file should truncate the .iso.

@GXTX
Copy link

GXTX commented Aug 30, 2023

Non-functional

pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-lz4
x86_64-w64-mingw32-g++ main.cpp -llz4 -static
./a /c/Temp/BarbieHorseAdventure/SEP13011042072.iso

Produces a ~2.6GB ISO that does not work.

@dracc
Copy link
Author

dracc commented Aug 30, 2023

Non-functional

pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-lz4
x86_64-w64-mingw32-g++ main.cpp -llz4 -static
./a /c/Temp/BarbieHorseAdventure/SEP13011042072.iso

Produces a ~2.6GB ISO that does not work.

Do you get a different result if you use the mingw64 packages (pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-lz4) instead of the ucrt stuff?

@GXTX
Copy link

GXTX commented Aug 30, 2023

Same thing.

@GXTX
Copy link

GXTX commented Aug 31, 2023

Same thing on WSL. Untested?

@dracc
Copy link
Author

dracc commented Oct 16, 2023

Same thing on WSL. Untested?

Works fine on my machines, both under Linux and MinGW64. Sorry, not sure what to tell you.
I've only tested Smashing Drive and Forza Motorsport so far, both in "xiso" format. What game(s) are you testing with?

@LoveMHz
Copy link
Contributor

LoveMHz commented Oct 17, 2023

Ah, damn. I had looked into this PR before and confirmed the issue that @GXTX was running into.

It appears related to large files, but I must have forgotten to track which flags must be set to build the code correctly.


ciso (std::ifstream &f) {
f.seekg(0, std::ios::end);
uint32_t file_size = (int32_t)f.tellg() - image_offset;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be causing issues, should (probably) be uint64_t instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That brings us closer at least; now redump input results in two files with reasonable sizes. Output doesn't match the python script past the header though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants