Gamecube GCM Lossless Encoder

LedZeppelin68
Posts: 80
Joined: Mon Jun 08, 2026 1:26 am

Re: Gamecube GCM Lossless Encoder

Post by LedZeppelin68 »

this is more recent and cleaned C# code from my new utility

uint blockcount - the full gc image is 1459978240 bytes long, it is divided in 262144 [0x40000] byte blocks
so first block is 0x00, second is 0x01 etc... until the end.

byte[] ID - 4-byte array,  first 4-bytes from image, gamecode

byte DiscNumber - 0x06 byte from image (Disc 1 == 0x00, Disc 2 == 0x01, etc)

Code: Select all

        private byte[] GetJunkBlock(uint blockcount, byte[] ID, byte DiscNumber)
        {
            uint[] buffer = new uint[0x824];
            byte[] GarbageBlock = new byte[0x40000];
            int i = 0, j = 0;
            uint sample = 0;

            blockcount = blockcount * 8 * 0x1ef29123;
            while (i != 0x40000)
            {
                if ((i & 0x00007fff) == 0)
                {
                    sample = (((((uint)ID[2] << 0x8) | ID[1]) << 0x10) | ((uint)(ID[3] + ID[2]) << 0x8)) | (uint)(ID[0] + ID[1]);
                    sample = ((sample ^ DiscNumber) * 0x260bcd5) ^ blockcount;
                    a10002710(sample, ref buffer);
                    j = 0x208;
                    blockcount += 0x1ef29123;
                }
                j++;
                if (j == 0x209)
                {
                    a100026e0(ref buffer);
                    j = 0;
                }

                GarbageBlock[i] = (byte)(buffer[j] >> 0x18);
                GarbageBlock[i + 1] = (byte)(buffer[j] >> 0x12);
                GarbageBlock[i + 2] = (byte)(buffer[j] >> 0x8);
                GarbageBlock[i + 3] = (byte)buffer[j];
                i += 4;
            }
            return GarbageBlock;
        }

        private void a10002710(uint sample, ref uint[] buffer)
        {
            uint temp = 0;
            int i = 0;
            while (i != 0x11)
            {
                for (int j = 0; j < 0x20; j++)
                {
                    sample *= 0x5d588b65;
                    temp = (temp >> 1) | (sample++ & 0x80000000);
                }
                buffer[i] = temp;
                i++;
            }

            buffer[0x10] ^= (buffer[0] >> 0x9) ^ (buffer[0x10] << 0x17);

            i = 1;
            while (i != 0x1f9)
            {
                buffer[i + 0x10] = ((buffer[i - 1] << 0x17) ^ (buffer[i] >> 0x9)) ^ buffer[i + 0xf];
                i++;
            }
            for (i = 0; i < 3; i++)
            {
                a100026e0(ref buffer);
            }
        }

        private void a100026e0(ref uint[] buffer)
        {
            int i = 0;
            while (i != 0x20)
            {
                buffer[i] ^= buffer[i + 0x1e9];
                i++;
            }
            while (i != 0x209)
            {
                buffer[i] ^= buffer[i - 0x20];
                i++;
            }
        }
LedZeppelin68
Posts: 80
Joined: Mon Jun 08, 2026 1:26 am

Re: Gamecube GCM Lossless Encoder

Post by LedZeppelin68 »

Jackal wrote:There is also a tool in the SDK for creating a double layer disc layout (it also shows the position of the security placeholders) and iirc it can also generate output images with padding?
padding with zeroes
User avatar
tossEAC
Posts: 1681
Joined: Mon Jun 08, 2026 1:26 am

Re: Gamecube GCM Lossless Encoder

Post by tossEAC »

Just thought I would let you know, Dead Space - Extraction (Europe) (En,Fr,De,It).iso.dec came out a few bytes bigger than as a raw iso...

4.37 GB (4,701,637,632 bytes) from 4.37 GB (4,699,979,776 bytes)

apart from that one, the tool works perfectly, and based on what I have converted, stripping the junk, and then torrent7zing the dec.iso makes savings of around 60% and this was over about 200 isos that I have.
He who controls the SPICE... controls the UNIVERSE!
The SPICE must flow.
User avatar
Pikmin
Posts: 416
Joined: Mon Jun 08, 2026 1:26 am

Re: Gamecube GCM Lossless Encoder

Post by Pikmin »

This is pretty amazing, now the fun of using this on 200+ isos begins, any chance there will be a Linux version?
Last edited by Pikmin on Wed Mar 30, 2016 3:48 am, edited 1 time in total.
do_0m
Posts: 40
Joined: Mon Jun 08, 2026 1:27 am

Re: Gamecube GCM Lossless Encoder

Post by do_0m »

Great tool. If there was a way to put a batch of ISOs through it, and after "compressing" each one, put each .dec file back through the program (in RAM) and verify the reformed ISO matches a certain (Redump) hash, it would be almost perfect. It doesn't have to follow that exact process, but I do want to be certain that the program doesn't distort any discs. There are enough strange GC and Wii ISOs that I can't be sure every single one of them complied with Nintendo's padding standard.

I'm not sure what causes it, but I can't seem to drag+drop on Windows 10 from the file explorer. I have to find an ISO with Everything search (third party program) and drag from there to NASOS.
Last edited by do_0m on Sun Apr 03, 2016 3:41 pm, edited 1 time in total.
LedZeppelin68
Posts: 80
Joined: Mon Jun 08, 2026 1:26 am

Re: Gamecube GCM Lossless Encoder

Post by LedZeppelin68 »

I have updated NASOS to alpha 4
If there was a way to put a batch of ISOs through it
NASOS already support it, just drag several ISOs

the only verification NASOS do is storing md5 of ISO in .dec file, and comparing it against md5 of decoded image

I wanna show you another tool, successor of NASOS, GameCube ISO Merger (do not works with Wii by now)
do_0m, it does all that you want.

the only difference, that besides removing garbage padding, it also removes duplicate data (like Walrus do)
and like Walrus, it merges all region clones of one game in one container

Merger - do batch merges (you can specify output folder, from one hdd to other, speed increase)
Archiver - 7z batch archiver, works with any files
Tester - unmerges in memory and verifies, also use it as batch unmerger
Log - shows info about gcmerge file

I have processed with it ~800 GC isos and ongoing.

the statistic is: 3 isos cannot be decoded properly

Sega Soccer Slam (Japan) - has error in file system
Doshin the Giant and Kyojin no Doshin have errors in garbage, unknown reason
Attachments
GameCubeISOMergerMarkI.rar
Imported Redump attachment 855
(732.35 KiB) Downloaded 1 time
Last edited by LedZeppelin68 on Mon Apr 04, 2016 3:12 pm, edited 1 time in total.
User avatar
tossEAC
Posts: 1681
Joined: Mon Jun 08, 2026 1:26 am

Re: Gamecube GCM Lossless Encoder

Post by tossEAC »

Can Nasos have this to... (you can specify output folder, from one hdd to other, speed increase)
He who controls the SPICE... controls the UNIVERSE!
The SPICE must flow.
Jackal
Posts: 2598
Joined: Mon Jun 08, 2026 1:26 am

Re: Gamecube GCM Lossless Encoder

Post by Jackal »

LedZeppelin68 wrote:I have processed with it ~800 GC isos and ongoing.

the statistic is: 3 isos cannot be decoded properly

Sega Soccer Slam (Japan) - has error in file system
Doshin the Giant and Kyojin no Doshin have errors in garbage, unknown reason
Maybe the first one is a bad dump? Is there a scene release to compare with?
Last edited by Jackal on Tue Apr 05, 2016 12:10 am, edited 1 time in total.
LedZeppelin68
Posts: 80
Joined: Mon Jun 08, 2026 1:26 am

Re: Gamecube GCM Lossless Encoder

Post by LedZeppelin68 »

Jackal wrote:
LedZeppelin68 wrote:I have processed with it ~800 GC isos and ongoing.

the statistic is: 3 isos cannot be decoded properly

Sega Soccer Slam (Japan) - has error in file system
Doshin the Giant and Kyojin no Doshin have errors in garbage, unknown reason
Maybe the first one is a bad dump? Is there a scene release to compare with?
it is not bad dump for sure

I'll show you
GameCube has its own filesystem - FST.

every file in FST have 12-byte record, divided in three 32bit big-endian values:

Code: Select all

Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00278030                                      00 00 09 70              ...p
00278040  29 01 D0 48 00 27 90 E1                          ).РH.'ђб
0x00000970 0x2901D048 0x002790E1

0x00000970 - first 0x00 means it is a file, (0x01 means a directory)
0x970 - is offset of file name (by the way it's name "soccerslam.dsf")

0x2901D048 - offset in image, where file starts
0x002790E1 - size of file

very simple

0x2901D048 + 0x002790E1 = 0x29296129 must be the end of file, but take a look, there is extra data after it
Image

maybe bad dump, but there is one thing, lets look inside the image, and there is interesting founding

soccerslam.ddf
soccerslam.dif
soccerslam.dlf
soccerslam.dol
soccerslam.dsf

this files used by official makegcm tool to build iso, look inside dif file, it is text file

0x000000c5=0,0x2901d048,0x002790e1,"soccerslam.dsf"
very similiar values

dif file used to make FST, but complete iso made using dsf, which does not have size values, only offset, where file belong
so editing dsf without updating dlf, brings this mastering error
LedZeppelin68
Posts: 80
Joined: Mon Jun 08, 2026 1:26 am

Re: Gamecube GCM Lossless Encoder

Post by LedZeppelin68 »

by the way, i've updated NASOS, let's call it beta 1, now with batch processing
Post Reply