Hacking Wii U Hacking & Homebrew Discussion

nastys

Well-Known Member
Member
Joined
Aug 5, 2014
Messages
1,732
Trophies
1
Age
26
Location
Earth
XP
1,807
Country
Italy
how to use cafiine?
  1. Run the OSDriver exploit
  2. Run the Cafiine installer
  3. Open the Cafiine server
  4. Start a game
  5. The server will tell you the ID of the game. Create a folder in cafiine_root and name it like the ID
  6. Restart the game
  7. The server will tell you the files that are being loaded from the disc or the folder you created
 

mariogamer

Well-Known Member
Member
Joined
Aug 12, 2015
Messages
1,256
Trophies
0
Age
28
XP
790
Country
Canada
  1. Run the OSDriver exploit
  2. Run the Cafiine installer
  3. Open the Cafiine server
  4. Start a game
  5. The server will tell you the ID of the game. Create a folder in cafiine_root and name it like the ID
  6. Restart the game
  7. The server will tell you the files that are being loaded from the disc or the folder you created

good explanation!
 
  • Like
Reactions: nastys

loco365

Well-Known Member
Member
Joined
Sep 1, 2010
Messages
5,457
Trophies
0
XP
2,927
Brawlcustommusic has a ton of bfstm files if you want a place to get started.

BTW I may try more DS VC Injection once I'm able to. I'd like to see what limitations it has.
 

VinsCool

Persona Secretiva Felineus
Global Moderator
Joined
Jan 7, 2014
Messages
14,600
Trophies
4
Location
Another World
Website
www.gbatemp.net
XP
25,228
Country
Canada
okay so I finally managed to set my local server, and got cafiine on it.

But, I'm hitting a wall now.

If I lauch cafiine, enter my pc ip address, and then attempt to load dk64, the console freezes.
If I load the game before, then load the browser from it, caffine seems to launch, but nothing seems to happen on my pc cafiine server app :(

I will try withn another and see if I can get it to work.
 

soneek

Well-Known Member
Member
Joined
Jun 27, 2012
Messages
179
Trophies
0
XP
337
Country
United States
I think the site does it behind the scenes because the stream data is encoded in a similar way, so they just grab the loop data and can freely switch between formats at will. I'm not 100% certain of this though, you'd have to get in touch with @soneek.

Pretty much. Here's a PHP script for going from brstm to bcstm or bfstm. Run it as
Code:
php brstmConv.php "song.brstm" bfstm

Code:
<?php


// Written by soneek [[email protected]][http://github.com/soneek]

function hex2str($hex) {    // from http://www.linux-support.com/cms/php-convert-hex-strings-to-ascii-strings/
    $str = '';
    for($i=0;$i<strlen($hex);$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
    return $str;
}

function read( $handle, $offset, $nbytes, $type/*bin=0 hex=1 dec=2*/, $endianFlag)
{
    fseek( $handle, $offset );
    if ($endianFlag)
        $output = strrev(fread( $handle, $nbytes ));
    else
        $output = fread( $handle, $nbytes );
    if ( $type != "b" ) {
        $output = bin2hex($output);
    }
    if ( $type == "d" ) {
        $output = hexdec( $output );
    }
    else if ($type == "s") {
        $output = hex2str($output);
    }
    return $output;
}


$file = $argv[1];
if ( !file_exists( $file ) ) {
    echo "File doesn't exist (" . $file . ")\n";
    exit;
}

else {
    if (!isset($argv[2]) || ($argv[2] != "bcstm" && $argv[2] != "bfstm"))
        $type = "bcstm";    // Default option will be bcstm output
    else
        $type = $argv[2];
  
    if (isset($argv[3]) && $argv[3] == "fea")
        $game = "fea";
    else
        $game = "";
      
    if ($type == "bcstm")
        $endFlag = true;
    else
        $endFlag = false;
  
    $brstm = fopen($file, "rb");
    if (read($brstm, 0, 4, "s", 0) != "RSTM") {
        echo "Not a brstm file\n";
        fclose($brstm);
        exit;
    }
    else {
        echo "BRSTM opened\n";
        $rstmSize = read($brstm, 8, 4, "d", $endFlag);
        $rstmInfoOffset = read($brstm, 0x10, 4, "d", 0);
        $rstmType = read($brstm, 0x60, 1, "d", $endFlag);
        if ($rstmType != 2) {
            echo "This only supports BRSTMs with the DSP-ADPCM codec\n";
            fclose($brstm);
            exit;
        }
        else {
            $rstmSize = read($brstm, 0x8, 4, "d", false);
            $rstmInfoSize = read($brstm, 0x14, 4, "d", false);
            $rstmSeekOffset = read($brstm, 0x18, 4, "d", false);
            $rstmSeekSize = read($brstm, 0x1c, 4, "d", false);
            $rstmDataOffset = read($brstm, 0x20, 4, "d", false);
            $rstmDataSize = read($brstm, 0x24, 4, "d", false);
          
            $rstmLoopFlag = read($brstm, 0x61, 1, "d", false);
            $rstmChannelCount = read($brstm, 0x62, 1, "d", false);
            $rstmSampleRate = read($brstm, 0x64, 2, "d", false);
            $rstmLoopStart = read($brstm, 0x68, 4, "d", false);
            $rstmSampleCount = read($brstm, 0x6c, 4, "d", false);
            $coeffPtr1 = read($brstm, 0x5c, 4, "d", false);
            $coeffPtr2 = read($brstm, $coeffPtr1 + 0x50, 4, "d", false);
            $coeffOffset = 0x50 + $coeffPtr2;
          
            // Opening output file
            $outfile = fopen(str_replace("brstm", $type, $file), "wb");
          
            if ($type == "bcstm") {
                fwrite($outfile, "CSTM" . pack("vvvnVvvvvVVvvVVvvV*", 0xfeff, 0x40, 0, 2, $rstmSize, 3, 0, 0x4000, 0, $rstmInfoOffset, $rstmInfoSize, 0x4001, 0, $rstmSeekOffset, $rstmSeekSize, 0x4002, 0, $rstmDataOffset, $rstmDataSize, 0, 0) . "INFO" . pack("VvvVvvVvvV", $rstmInfoSize, 0x4100, 0, 0x18, 0x101, 0, 0x50, 0x101, 0, 0x54 + ceil($rstmChannelCount / 2) * 8) . pack("CCCCV*", $rstmType, $rstmLoopFlag, $rstmChannelCount, 0, $rstmSampleRate, $rstmLoopStart, $rstmSampleCount));
                for ($i = 0; $i < 6; $i++)
                    fwrite($outfile, read($brstm, 0x74 + $i * 4, 4, "b", $endFlag));
                fwrite($outfile, pack("VVvvVV", 4, 0x3800, 0x1f00, 0, 0x18, ceil($rstmChannelCount / 2)));
                for ($i = 0; $i < ceil($rstmChannelCount / 2); $i++)
                    fwrite($outfile, pack("vvV", 0x4101, 0, $rstmChannelCount * 12 + 8 + $i * 0x14));
                fwrite($outfile, pack("V", $rstmChannelCount));
                for ($i = 0; $i < $rstmChannelCount; $i++)
                    fwrite($outfile, pack("vvV", 0x4102, 0, 4 + $rstmChannelCount * 8 + ($rstmChannelCount / 2) * 0x14 + $i * 8));
                $rstmBlahMetaDataOffset = read($brstm, 0x9c, 4, "d", false);
                for ($i = 0; $i < $rstmChannelCount / 2; $i++) {
                    if ($game == "fea" && $i == 0)
                        fwrite($outfile, pack("CCvvvVVccv", 0x73, 64, 0, 0x100, 0, 0xc, 2, 2 * $i, 2 * $i + 1, 0));
                    else
                        fwrite($outfile, pack("CCvvvVVccv", 127, 64, 0, 0x100, 0, 0xc, 2, 2 * $i, 2 * $i + 1, 0));
                }
                for ($i = 0; $i < $rstmChannelCount; $i++)
                    fwrite($outfile, pack("vvV", 0x300, 0, $rstmChannelCount * 8 + $i * 0x26));  
              
                // Now to write coefficients and stuff

                for ($i = 0; $i < $rstmChannelCount; $i++) {
                    for ($j = 0; $j < 16; $j++)
                        fwrite($outfile, read($brstm, $coeffOffset + $i * 0x38 + $j * 2, 2, "b", $endFlag));
                    for ($j = 0; $j < 7; $j++)
                        fwrite($outfile, read($brstm, $coeffOffset + $i * 0x38 + $j * 2 + 0x22, 2, "b", $endFlag));
                }
              
                // Padding the file
                if ((ftell($outfile) % 16) != 0)
                    $padlength = 16 - (ftell($outfile) % 16);
                else
                    $padlength = 0;
                for ($i = 0; $i < $padlength; $i++)
                    fwrite($outfile, pack("C", 0));
                $infoSizeDifference = $rstmInfoSize + $rstmInfoOffset - ftell($outfile);
                echo $rstmInfoOffset;
                fseek($outfile, 0xc, SEEK_SET);
                fwrite($outfile, pack("V", $rstmSize - $infoSizeDifference));
                fseek($outfile, 0x1c, SEEK_SET);
                fwrite($outfile, pack("V", $rstmInfoSize - $infoSizeDifference));
                fseek($outfile, 0x24, SEEK_SET);
                fwrite($outfile, pack("V", $rstmSeekOffset - $infoSizeDifference));
                fseek($outfile, 0x30, SEEK_SET);
                fwrite($outfile, pack("V", $rstmDataOffset - $infoSizeDifference));
                fseek($outfile, 0, SEEK_END);
                fseek($brstm, $rstmSeekOffset + 0x10, SEEK_SET);
                fwrite($outfile, "SEEK" . pack("V*", $rstmSeekSize, 0, 0));
                for ($i = 0; $i < ($rstmSeekSize - 16) / 2; $i++)
                    fwrite($outfile, strrev(fread($brstm, 2)));
                fseek($brstm, $rstmDataOffset + 0x20, SEEK_SET);
                fwrite($outfile, "DATA" . pack("V*", $rstmDataSize, 0, 0, 0, 0, 0, 0));
              
            }
          
            // Converting BRSTM to BFSTM
          
            else if ($type == "bfstm") {
                fwrite($outfile, "FSTM" . pack("nnnnNnnnnNNnnNNnnN*", 0xfeff, 0x40, 3, 0, $rstmSize, 3, 0, 0x4000, 0, $rstmInfoOffset, $rstmInfoSize, 0x4001, 0, $rstmSeekOffset, $rstmSeekSize, 0x4002, 0, $rstmDataOffset, $rstmDataSize, 0, 0) . "INFO" . pack("NnnNnnNnnN", $rstmInfoSize, 0x4100, 0, 0x18, 0x101, 0, 0x50, 0x101, 0, 0x54 + ceil($rstmChannelCount / 2) * 8) . pack("CCCCN*", $rstmType, $rstmLoopFlag, $rstmChannelCount, 0, $rstmSampleRate, $rstmLoopStart, $rstmSampleCount));
                              
                for ($i = 0; $i < 6; $i++)
                    fwrite($outfile, read($brstm, 0x74 + $i * 4, 4, "b", $endFlag));
                fwrite($outfile, pack("NNnnNV", 4, 0x3800, 0x1f00, 0, 0x18, ceil($rstmChannelCount / 2)));
                for ($i = 0; $i < ceil($rstmChannelCount / 2); $i++)
                    fwrite($outfile, pack("nnN", 0x4101, 0, $rstmChannelCount * 12 + 8 + $i * 0x14));
                fwrite($outfile, pack("N", $rstmChannelCount));
                for ($i = 0; $i < $rstmChannelCount; $i++)
                    fwrite($outfile, pack("nnN", 0x4102, 0, 4 + $rstmChannelCount * 8 + ceil($rstmChannelCount / 2) * 0x14 + $i * 8));
                for ($i = 0; $i < $rstmChannelCount / 2; $i++) {
                    fwrite($outfile, pack("CCnNNNCCn", 127, 64, 0, 0x100, 0xc, 2, 2 * $i, 2 * $i + 1, 0));      
                }
                for ($i = 0; $i < $rstmChannelCount; $i++)
                    fwrite($outfile, pack("nnN", 0x300, 0, $rstmChannelCount * 8 + $i * 0x26));  
                for ($i = 0; $i < $rstmChannelCount; $i++) {
                    for ($j = 0; $j < 16; $j++)
                        fwrite($outfile, read($brstm, $coeffOffset + $i * 0x38 + $j * 2, 2, "b", $endFlag));
                    for ($j = 0; $j < 7; $j++)
                        fwrite($outfile, read($brstm, $coeffOffset + $i * 0x38 + $j * 2 + 0x22, 2, "b", $endFlag));
                }
              
                // Padding the file
                if ((ftell($outfile) % 16) != 0)
                    $padlength = 16 - (ftell($outfile) % 16);
                else
                    $padlength = 0;
                for ($i = 0; $i < $padlength; $i++)
                    fwrite($outfile, pack("C", 0));
                $infoSizeDifference = $rstmInfoSize + $rstmInfoOffset - ftell($outfile);
                echo $rstmInfoOffset;
                fseek($outfile, 0xc, SEEK_SET);
                fwrite($outfile, pack("N", $rstmSize - $infoSizeDifference));
                fseek($outfile, 0x1c, SEEK_SET);
                fwrite($outfile, pack("N", $rstmInfoSize - $infoSizeDifference));
                fseek($outfile, 0x24, SEEK_SET);
                fwrite($outfile, pack("N", $rstmSeekOffset - $infoSizeDifference));
                fseek($outfile, 0x30, SEEK_SET);
                fwrite($outfile, pack("N", $rstmDataOffset - $infoSizeDifference));
                fseek($outfile, 0, SEEK_END);
                fseek($brstm, $rstmSeekOffset + 0x10, SEEK_SET);
                fwrite($outfile, "SEEK" . pack("N*", $rstmSeekSize, 0, 0));
                for ($i = 0; $i < ($rstmSeekSize - 16) / 2; $i++)
                    fwrite($outfile, fread($brstm, 2));
                fseek($brstm, $rstmDataOffset + 0x20, SEEK_SET);
                fwrite($outfile, "DATA" . pack("N*", $rstmDataSize, 0, 0, 0, 0, 0, 0));
            }
          
            // The DATA portion is exactly the same, between B(R/C/F)STM,  so we can copy the rest as is
            while(!feof($brstm))
                fwrite($outfile, fread($brstm, 1024 * 8));
          
        }
    }
    fclose($outfile);
    fclose($brstm);
}

?>

If someone really wanted to, they could write a b*stm to b*stm re-writer. The song data is exactly the same, but the headers and previous sections are structure a little differently.
 
  • Like
Reactions: nastys and loco365

VinsCool

Persona Secretiva Felineus
Global Moderator
Joined
Jan 7, 2014
Messages
14,600
Trophies
4
Location
Another World
Website
www.gbatemp.net
XP
25,228
Country
Canada
Success! I got it! Cafiine ftw!

IMG_20150825_175544.jpg
 

VinsCool

Persona Secretiva Felineus
Global Moderator
Joined
Jan 7, 2014
Messages
14,600
Trophies
4
Location
Another World
Website
www.gbatemp.net
XP
25,228
Country
Canada
How does save data work? For example, you start a save in Banjo-Kazooie, then load the default VC game, play it, then load Banjo-Kazooie again thru Cafiine. Is the BK save data still intact?
I will try :P

--------------------- MERGED ---------------------------

How does save data work? For example, you start a save in Banjo-Kazooie, then load the default VC game, play it, then load Banjo-Kazooie again thru Cafiine. Is the BK save data still intact?
My save state still work after reloading dk64. then exiting and reloading banjo kazooie :P

I can't tell about sram, but dk64 sram remained intact it seems.
 

nastys

Well-Known Member
Member
Joined
Aug 5, 2014
Messages
1,732
Trophies
1
Age
26
Location
Earth
XP
1,807
Country
Italy
Pretty much. Here's a PHP script for going from brstm to bcstm or bfstm. Run it as
Code:
php brstmConv.php "song.brstm" bfstm

Code:
<?php


// Written by soneek [[email protected]][http://github.com/soneek]

function hex2str($hex) {    // from http://www.linux-support.com/cms/php-convert-hex-strings-to-ascii-strings/
    $str = '';
    for($i=0;$i<strlen($hex);$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
    return $str;
}

function read( $handle, $offset, $nbytes, $type/*bin=0 hex=1 dec=2*/, $endianFlag)
{
    fseek( $handle, $offset );
    if ($endianFlag)
        $output = strrev(fread( $handle, $nbytes ));
    else
        $output = fread( $handle, $nbytes );
    if ( $type != "b" ) {
        $output = bin2hex($output);
    }
    if ( $type == "d" ) {
        $output = hexdec( $output );
    }
    else if ($type == "s") {
        $output = hex2str($output);
    }
    return $output;
}


$file = $argv[1];
if ( !file_exists( $file ) ) {
    echo "File doesn't exist (" . $file . ")\n";
    exit;
}

else {
    if (!isset($argv[2]) || ($argv[2] != "bcstm" && $argv[2] != "bfstm"))
        $type = "bcstm";    // Default option will be bcstm output
    else
        $type = $argv[2];
 
    if (isset($argv[3]) && $argv[3] == "fea")
        $game = "fea";
    else
        $game = "";
     
    if ($type == "bcstm")
        $endFlag = true;
    else
        $endFlag = false;
 
    $brstm = fopen($file, "rb");
    if (read($brstm, 0, 4, "s", 0) != "RSTM") {
        echo "Not a brstm file\n";
        fclose($brstm);
        exit;
    }
    else {
        echo "BRSTM opened\n";
        $rstmSize = read($brstm, 8, 4, "d", $endFlag);
        $rstmInfoOffset = read($brstm, 0x10, 4, "d", 0);
        $rstmType = read($brstm, 0x60, 1, "d", $endFlag);
        if ($rstmType != 2) {
            echo "This only supports BRSTMs with the DSP-ADPCM codec\n";
            fclose($brstm);
            exit;
        }
        else {
            $rstmSize = read($brstm, 0x8, 4, "d", false);
            $rstmInfoSize = read($brstm, 0x14, 4, "d", false);
            $rstmSeekOffset = read($brstm, 0x18, 4, "d", false);
            $rstmSeekSize = read($brstm, 0x1c, 4, "d", false);
            $rstmDataOffset = read($brstm, 0x20, 4, "d", false);
            $rstmDataSize = read($brstm, 0x24, 4, "d", false);
         
            $rstmLoopFlag = read($brstm, 0x61, 1, "d", false);
            $rstmChannelCount = read($brstm, 0x62, 1, "d", false);
            $rstmSampleRate = read($brstm, 0x64, 2, "d", false);
            $rstmLoopStart = read($brstm, 0x68, 4, "d", false);
            $rstmSampleCount = read($brstm, 0x6c, 4, "d", false);
            $coeffPtr1 = read($brstm, 0x5c, 4, "d", false);
            $coeffPtr2 = read($brstm, $coeffPtr1 + 0x50, 4, "d", false);
            $coeffOffset = 0x50 + $coeffPtr2;
         
            // Opening output file
            $outfile = fopen(str_replace("brstm", $type, $file), "wb");
         
            if ($type == "bcstm") {
                fwrite($outfile, "CSTM" . pack("vvvnVvvvvVVvvVVvvV*", 0xfeff, 0x40, 0, 2, $rstmSize, 3, 0, 0x4000, 0, $rstmInfoOffset, $rstmInfoSize, 0x4001, 0, $rstmSeekOffset, $rstmSeekSize, 0x4002, 0, $rstmDataOffset, $rstmDataSize, 0, 0) . "INFO" . pack("VvvVvvVvvV", $rstmInfoSize, 0x4100, 0, 0x18, 0x101, 0, 0x50, 0x101, 0, 0x54 + ceil($rstmChannelCount / 2) * 8) . pack("CCCCV*", $rstmType, $rstmLoopFlag, $rstmChannelCount, 0, $rstmSampleRate, $rstmLoopStart, $rstmSampleCount));
                for ($i = 0; $i < 6; $i++)
                    fwrite($outfile, read($brstm, 0x74 + $i * 4, 4, "b", $endFlag));
                fwrite($outfile, pack("VVvvVV", 4, 0x3800, 0x1f00, 0, 0x18, ceil($rstmChannelCount / 2)));
                for ($i = 0; $i < ceil($rstmChannelCount / 2); $i++)
                    fwrite($outfile, pack("vvV", 0x4101, 0, $rstmChannelCount * 12 + 8 + $i * 0x14));
                fwrite($outfile, pack("V", $rstmChannelCount));
                for ($i = 0; $i < $rstmChannelCount; $i++)
                    fwrite($outfile, pack("vvV", 0x4102, 0, 4 + $rstmChannelCount * 8 + ($rstmChannelCount / 2) * 0x14 + $i * 8));
                $rstmBlahMetaDataOffset = read($brstm, 0x9c, 4, "d", false);
                for ($i = 0; $i < $rstmChannelCount / 2; $i++) {
                    if ($game == "fea" && $i == 0)
                        fwrite($outfile, pack("CCvvvVVccv", 0x73, 64, 0, 0x100, 0, 0xc, 2, 2 * $i, 2 * $i + 1, 0));
                    else
                        fwrite($outfile, pack("CCvvvVVccv", 127, 64, 0, 0x100, 0, 0xc, 2, 2 * $i, 2 * $i + 1, 0));
                }
                for ($i = 0; $i < $rstmChannelCount; $i++)
                    fwrite($outfile, pack("vvV", 0x300, 0, $rstmChannelCount * 8 + $i * 0x26)); 
             
                // Now to write coefficients and stuff

                for ($i = 0; $i < $rstmChannelCount; $i++) {
                    for ($j = 0; $j < 16; $j++)
                        fwrite($outfile, read($brstm, $coeffOffset + $i * 0x38 + $j * 2, 2, "b", $endFlag));
                    for ($j = 0; $j < 7; $j++)
                        fwrite($outfile, read($brstm, $coeffOffset + $i * 0x38 + $j * 2 + 0x22, 2, "b", $endFlag));
                }
             
                // Padding the file
                if ((ftell($outfile) % 16) != 0)
                    $padlength = 16 - (ftell($outfile) % 16);
                else
                    $padlength = 0;
                for ($i = 0; $i < $padlength; $i++)
                    fwrite($outfile, pack("C", 0));
                $infoSizeDifference = $rstmInfoSize + $rstmInfoOffset - ftell($outfile);
                echo $rstmInfoOffset;
                fseek($outfile, 0xc, SEEK_SET);
                fwrite($outfile, pack("V", $rstmSize - $infoSizeDifference));
                fseek($outfile, 0x1c, SEEK_SET);
                fwrite($outfile, pack("V", $rstmInfoSize - $infoSizeDifference));
                fseek($outfile, 0x24, SEEK_SET);
                fwrite($outfile, pack("V", $rstmSeekOffset - $infoSizeDifference));
                fseek($outfile, 0x30, SEEK_SET);
                fwrite($outfile, pack("V", $rstmDataOffset - $infoSizeDifference));
                fseek($outfile, 0, SEEK_END);
                fseek($brstm, $rstmSeekOffset + 0x10, SEEK_SET);
                fwrite($outfile, "SEEK" . pack("V*", $rstmSeekSize, 0, 0));
                for ($i = 0; $i < ($rstmSeekSize - 16) / 2; $i++)
                    fwrite($outfile, strrev(fread($brstm, 2)));
                fseek($brstm, $rstmDataOffset + 0x20, SEEK_SET);
                fwrite($outfile, "DATA" . pack("V*", $rstmDataSize, 0, 0, 0, 0, 0, 0));
             
            }
         
            // Converting BRSTM to BFSTM
         
            else if ($type == "bfstm") {
                fwrite($outfile, "FSTM" . pack("nnnnNnnnnNNnnNNnnN*", 0xfeff, 0x40, 3, 0, $rstmSize, 3, 0, 0x4000, 0, $rstmInfoOffset, $rstmInfoSize, 0x4001, 0, $rstmSeekOffset, $rstmSeekSize, 0x4002, 0, $rstmDataOffset, $rstmDataSize, 0, 0) . "INFO" . pack("NnnNnnNnnN", $rstmInfoSize, 0x4100, 0, 0x18, 0x101, 0, 0x50, 0x101, 0, 0x54 + ceil($rstmChannelCount / 2) * 8) . pack("CCCCN*", $rstmType, $rstmLoopFlag, $rstmChannelCount, 0, $rstmSampleRate, $rstmLoopStart, $rstmSampleCount));
                             
                for ($i = 0; $i < 6; $i++)
                    fwrite($outfile, read($brstm, 0x74 + $i * 4, 4, "b", $endFlag));
                fwrite($outfile, pack("NNnnNV", 4, 0x3800, 0x1f00, 0, 0x18, ceil($rstmChannelCount / 2)));
                for ($i = 0; $i < ceil($rstmChannelCount / 2); $i++)
                    fwrite($outfile, pack("nnN", 0x4101, 0, $rstmChannelCount * 12 + 8 + $i * 0x14));
                fwrite($outfile, pack("N", $rstmChannelCount));
                for ($i = 0; $i < $rstmChannelCount; $i++)
                    fwrite($outfile, pack("nnN", 0x4102, 0, 4 + $rstmChannelCount * 8 + ceil($rstmChannelCount / 2) * 0x14 + $i * 8));
                for ($i = 0; $i < $rstmChannelCount / 2; $i++) {
                    fwrite($outfile, pack("CCnNNNCCn", 127, 64, 0, 0x100, 0xc, 2, 2 * $i, 2 * $i + 1, 0));     
                }
                for ($i = 0; $i < $rstmChannelCount; $i++)
                    fwrite($outfile, pack("nnN", 0x300, 0, $rstmChannelCount * 8 + $i * 0x26)); 
                for ($i = 0; $i < $rstmChannelCount; $i++) {
                    for ($j = 0; $j < 16; $j++)
                        fwrite($outfile, read($brstm, $coeffOffset + $i * 0x38 + $j * 2, 2, "b", $endFlag));
                    for ($j = 0; $j < 7; $j++)
                        fwrite($outfile, read($brstm, $coeffOffset + $i * 0x38 + $j * 2 + 0x22, 2, "b", $endFlag));
                }
             
                // Padding the file
                if ((ftell($outfile) % 16) != 0)
                    $padlength = 16 - (ftell($outfile) % 16);
                else
                    $padlength = 0;
                for ($i = 0; $i < $padlength; $i++)
                    fwrite($outfile, pack("C", 0));
                $infoSizeDifference = $rstmInfoSize + $rstmInfoOffset - ftell($outfile);
                echo $rstmInfoOffset;
                fseek($outfile, 0xc, SEEK_SET);
                fwrite($outfile, pack("N", $rstmSize - $infoSizeDifference));
                fseek($outfile, 0x1c, SEEK_SET);
                fwrite($outfile, pack("N", $rstmInfoSize - $infoSizeDifference));
                fseek($outfile, 0x24, SEEK_SET);
                fwrite($outfile, pack("N", $rstmSeekOffset - $infoSizeDifference));
                fseek($outfile, 0x30, SEEK_SET);
                fwrite($outfile, pack("N", $rstmDataOffset - $infoSizeDifference));
                fseek($outfile, 0, SEEK_END);
                fseek($brstm, $rstmSeekOffset + 0x10, SEEK_SET);
                fwrite($outfile, "SEEK" . pack("N*", $rstmSeekSize, 0, 0));
                for ($i = 0; $i < ($rstmSeekSize - 16) / 2; $i++)
                    fwrite($outfile, fread($brstm, 2));
                fseek($brstm, $rstmDataOffset + 0x20, SEEK_SET);
                fwrite($outfile, "DATA" . pack("N*", $rstmDataSize, 0, 0, 0, 0, 0, 0));
            }
         
            // The DATA portion is exactly the same, between B(R/C/F)STM,  so we can copy the rest as is
            while(!feof($brstm))
                fwrite($outfile, fread($brstm, 1024 * 8));
         
        }
    }
    fclose($outfile);
    fclose($brstm);
}

?>

If someone really wanted to, they could write a b*stm to b*stm re-writer. The song data is exactly the same, but the headers and previous sections are structure a little differently.
Thank you, it worked!!! :lol:
May I add it to BRSTM/BCSTM Conversion Tool, so that it becomes BRSTM/BCSTM/BFSTM Conversion Tool? :lol:
I'll add your name to the button if you let me :lol:
 
  • Like
Reactions: soneek

the_randomizer

The Temp's official fox whisperer
Member
Joined
Apr 29, 2011
Messages
31,284
Trophies
2
Age
38
Location
Dr. Wahwee's castle
XP
18,969
Country
United States
Success! I got it! Cafiine ftw!

View attachment 23989

*Sees attachment, weeps bitterly as I realize how far behind I am*

Any sound? Oh man....I've been missing a lot. No tutorials, no actual guides how to do ROM injections.....*sigh* c'est la vie. :(

So far behind I don't even know if I can catch up at this point.
 

VinsCool

Persona Secretiva Felineus
Global Moderator
Joined
Jan 7, 2014
Messages
14,600
Trophies
4
Location
Another World
Website
www.gbatemp.net
XP
25,228
Country
Canada
*Sees attachment, weeps bitterly as I realize how far behind I am*

Any sound? Oh man....I've been missing a lot. No tutorials, no actual guides how to do ROM injections.....*sigh* c'est la vie. :(

So far behind I don't even know if I can catch up at this point.
There is sound, save and rumble :P

Tutorials? I got one (in french) by markus95 at logic-sunrise) ;)

There are tutorials at gbatemp too ;)
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BigOnYa @ BigOnYa:
    Did you feed the hamster in your internet router? It prob died and is running slow now.
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, why did you start saying my pc has a hamster in the first place?
    +1
  • BigOnYa @ BigOnYa:
    Its actua!ly just a old joke, meaning its slow. Was just kidding around with you.
    +1
  • BigOnYa @ BigOnYa:
    I bet @AncientBoi has some hamsters hidden somewhere tho....
    +2
  • Psionic Roshambo @ Psionic Roshambo:
    I think Game streaming should work like this.... Local Hardware able the run the game fine, game engine and common assets stored locally, all FMV and music and textures could be streaming
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Some temporary storage
  • Xdqwerty @ Xdqwerty:
    also @BigOnYa im making some progress on my gdevelop project, implemented various mechanics
  • Psionic Roshambo @ Psionic Roshambo:
    They went all in on streaming, should have been more of a hybrid approach
    +1
  • BigOnYa @ BigOnYa:
    Or free government supplied high speed internet be nice also. Like Obama care. Xdqwerty that's cool, its time consuming but rewarding once done or playable, to see what you've made from scratch. Animations take forever, but worth it.
    +1
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, although the bullets are a bit buggy
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Not to mention this would be a massive pain to pirate
  • Xdqwerty @ Xdqwerty:
    @BigOnYa,
    and the visual aspect of the game is quite crude (the sprite that looks best is that of the protagonist just because he is a stickman with sunglasses)
    +1
  • BigOnYa @ BigOnYa:
    There is a bullets behaviour you assign to your character, that makes the code easier, under "behaviours"
  • Xdqwerty @ Xdqwerty:
    i meant that when the character is pointing to the right, the bullets spawn where they should, but when he is on the right, they move to the right but the spawn point is incorrect
  • BigOnYa @ BigOnYa:
    Itch.io has lots of free assets also. Under the bullets behavior tab, there is a "rotate bullets" option, can try that. Or in the code can try
    - fire bullet Player.X(PlayerDirection)
  • Xdqwerty @ Xdqwerty:
    im taking a break for today anyway
    +1
  • BigOnYa @ BigOnYa:
    YEa gotta after a while, looking at code for long periods will bug your eyes.
    +1
  • BigOnYa @ BigOnYa:
    That's cool tho, I'm proud of you going back to it, not giving up. It is difficult at first to learn, but fun once you get the hang of it. I think I've watched every tutorial video there is, but I still struggle sometimes to get stuff to work right. But gotta keep trying dif things, and eventually you will get it right.
    +1
  • K3Nv2 @ K3Nv2:
    Lol McDonald's has a grandma mcflurry
  • Xdqwerty @ Xdqwerty:
    @K3Nv2, furry grandma?
  • BigOnYa @ BigOnYa:
    It sounds good actually, I like butterscotch
  • K3Nv2 @ K3Nv2:
    It sucked don't know wtf these little bits and pieces are they use now
    +1
    K3Nv2 @ K3Nv2: It sucked don't know wtf these little bits and pieces are they use now +1