Skip to content

Commit 715d798

Browse files
rapperskullLukeUsher
authored andcommitted
Add support for XGD1
Use correct offset when rewriting from XDG ISO
1 parent f6d8223 commit 715d798

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

extract-xiso.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,9 @@
441441
#endif
442442

443443

444-
#define GLOBAL_LSEEK_OFFSET 0xFD90000ul
445-
#define XGD3_LSEEK_OFFSET 0x2080000ul
444+
#define GLOBAL_LSEEK_OFFSET 0x0FD90000ul
445+
#define XGD3_LSEEK_OFFSET 0x02080000ul
446+
#define XGD1_LSEEK_OFFSET 0x18300000ul
446447

447448
#define n_sectors( size ) ( ( size ) / XISO_SECTOR_SIZE + ( ( size ) % XISO_SECTOR_SIZE ? 1 : 0 ) )
448449

@@ -882,18 +883,24 @@ int verify_xiso( int in_xiso, int32_t *out_root_dir_sector, int32_t *out_root_di
882883
if ( ! err && read( in_xiso, buffer, XISO_HEADER_DATA_LENGTH ) != XISO_HEADER_DATA_LENGTH ) read_err();
883884
if ( ! err && memcmp( buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH ) )
884885
{
885-
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + GLOBAL_LSEEK_OFFSET, SEEK_SET ) == -1 ) seek_err();
886-
if ( ! err && read( in_xiso, buffer, XISO_HEADER_DATA_LENGTH ) != XISO_HEADER_DATA_LENGTH ) read_err();
887-
if ( ! err && memcmp( buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH ) ) {
888-
889-
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + XGD3_LSEEK_OFFSET, SEEK_SET ) == -1 ) seek_err();
890-
if ( ! err && read( in_xiso, buffer, XISO_HEADER_DATA_LENGTH ) != XISO_HEADER_DATA_LENGTH ) read_err();
891-
if ( ! err && memcmp( buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH ) ) misc_err( "%s does not appear to be a valid xbox iso image\n", in_iso_name, 0, 0 )
892-
else s_xbox_disc_lseek = XGD3_LSEEK_OFFSET;
893-
}
894-
else s_xbox_disc_lseek = GLOBAL_LSEEK_OFFSET;
895-
}
896-
else s_xbox_disc_lseek = 0;
886+
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + GLOBAL_LSEEK_OFFSET, SEEK_SET ) == -1 ) seek_err();
887+
if ( ! err && read( in_xiso, buffer, XISO_HEADER_DATA_LENGTH ) != XISO_HEADER_DATA_LENGTH ) read_err();
888+
if ( ! err && memcmp( buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH ) )
889+
{
890+
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + XGD3_LSEEK_OFFSET, SEEK_SET ) == -1 ) seek_err();
891+
if ( ! err && read( in_xiso, buffer, XISO_HEADER_DATA_LENGTH ) != XISO_HEADER_DATA_LENGTH ) read_err();
892+
if (!err && memcmp(buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH))
893+
{
894+
if (lseek(in_xiso, (xoff_t)XISO_HEADER_OFFSET + XGD1_LSEEK_OFFSET, SEEK_SET) == -1) seek_err();
895+
if (!err && read(in_xiso, buffer, XISO_HEADER_DATA_LENGTH) != XISO_HEADER_DATA_LENGTH) read_err();
896+
if (!err && memcmp(buffer, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH)) misc_err("%s does not appear to be a valid xbox iso image\n", in_iso_name, 0, 0)
897+
else s_xbox_disc_lseek = XGD1_LSEEK_OFFSET;
898+
}
899+
else s_xbox_disc_lseek = XGD3_LSEEK_OFFSET;
900+
}
901+
else s_xbox_disc_lseek = GLOBAL_LSEEK_OFFSET;
902+
}
903+
else s_xbox_disc_lseek = 0;
897904

898905
// read root directory information
899906
if ( ! err && read( in_xiso, out_root_dir_sector, XISO_SECTOR_OFFSET_SIZE ) != XISO_SECTOR_OFFSET_SIZE ) read_err();
@@ -1022,7 +1029,7 @@ int create_xiso( char *in_root_directory, char *in_output_directory, dir_node_av
10221029
}
10231030
if ( ! err ) {
10241031
if ( in_root ) {
1025-
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + XISO_HEADER_DATA_LENGTH + XISO_SECTOR_OFFSET_SIZE + XISO_DIRTABLE_SIZE, SEEK_SET ) == -1 ) seek_err();
1032+
if ( lseek( in_xiso, (xoff_t) XISO_HEADER_OFFSET + XISO_HEADER_DATA_LENGTH + XISO_SECTOR_OFFSET_SIZE + XISO_DIRTABLE_SIZE + s_xbox_disc_lseek, SEEK_SET ) == -1 ) seek_err();
10261033
if ( ! err && read( in_xiso, buf, XISO_FILETIME_SIZE ) != XISO_FILETIME_SIZE ) read_err();
10271034
if ( ! err && write( xiso, buf, XISO_FILETIME_SIZE ) != XISO_FILETIME_SIZE ) write_err();
10281035

@@ -1738,7 +1745,7 @@ int write_file( dir_node_avl *in_avl, write_tree_context *in_context, int in_dep
17381745
if ( in_context->from == -1 ) {
17391746
if ( ( fd = open( in_avl->filename, READFLAGS, 0 ) ) == -1 ) open_err( in_avl->filename );
17401747
} else {
1741-
if ( lseek( fd = in_context->from, (xoff_t) in_avl->old_start_sector * XISO_SECTOR_SIZE, SEEK_SET ) == -1 ) seek_err();
1748+
if ( lseek( fd = in_context->from, (xoff_t) in_avl->old_start_sector * XISO_SECTOR_SIZE + s_xbox_disc_lseek, SEEK_SET ) == -1 ) seek_err();
17421749
}
17431750
}
17441751

0 commit comments

Comments
 (0)